Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Displaying another field values

Posted on 2000-05-09
3
Medium Priority
?
198 Views
Last Modified: 2010-04-04
Imagine a TNumericField descendant named MYFIELD. Values contained in this field are integers. I want to somehow modify the field's value but only for displaying purposes. For example If the MZFIELD contains a value of 1 I want to display in DBGrid a string "one", if the value is 2 I want to display string "two" and so on. I have played a little with OnGetText event of TField but I always got an exception "'' is not valid integer value". I tried the code below also on TStringField and I've got no exception but all MYFIELD's values has disappeared. What Iam doing wrong. Please help, Ivo.

The code is:

TForm1.MYFIELDGetText(...)
begin
  if (Sender = MYFIELD) and Text = '1' then
    Text:= 'one';
end;
0
Comment
Question by:ivobauer
3 Comments
 
LVL 6

Expert Comment

by:Jaymol
ID: 2791994
Handle the conversion in whatever component it is that you use to show the value, not in the actual field.

John.
0
 
LVL 27

Accepted Solution

by:
kretzschmar earned 200 total points
ID: 2792001
hi ivo,

you must lookup to sender fieldvalue like

GetTextEvent
begin
  if (Sender = MYFIELD) then
    If Sender.AsInteger = 1 then
      Text:= 'one'
    else
      Text := Sender.AsString;
end

also you must do a vice-versa with SetText like

SetTextEvent
begin
  if (Sender = MYFIELD) then
    If Text = 'one' then
      Sender.AsInteger := 1;
    else
      Try
        Sender.AsInteger := IntToStr(text);
      except
        raise;
      end;
end

hope this helps

meikl
0
 
LVL 2

Author Comment

by:ivobauer
ID: 2799798
Meikl: Thanks for the proposed answer, it helped me a lot again! I am transferring the points to your account. Do you remember when we talked about an updatable query? Can you send me your e-mail (I lost it) to Ivo.Bauer@upce.cz, I have something to say to you.
Once more - thanks to you.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Screencast - Getting to Know the Pipeline
Suggested Courses

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question