Solved

Displaying another field values

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

911 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

20 Experts available now in Live!

Get 1:1 Help Now