Solved

Displaying another field values

Posted on 2000-05-09
3
176 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 50 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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
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…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

759 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now