Solved

How do I create a calculated field at RUNTIME?

Posted on 2002-04-15
4
1,088 Views
Last Modified: 2012-06-27
I can't afford the luxury of right clicking on the TTable and adding ALL fields and then adding my calculated field as this gives problems @ runtime when field names/types change.  I want to create a calculated field and a lookup field @ runtime.  How do I go about this?
0
Comment
Question by:djadja
  • 3
4 Comments
 
LVL 1

Accepted Solution

by:
Alone earned 100 total points
ID: 6944004
Try this:

type
  TMyForm = class(TForm)
    Table1: TTable;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    MyStringField: TStringField;
    MyFloatField: TFloatField;
  end;

{ TMyForm }

procedure TMyForm.Button1Click(Sender: TObject);
begin
  Table1.Close;
  MyStringField := TStringField.Create(Self);
  with MyStringField do
  begin
    FieldKind := fkCalculated;
    FieldName := 'MyString';
    Size := 100;
    DataSet := Table1;
  end;
  MyFloatField := TFloatField.Create(Self);
  with MyFloatField do
  begin
    FieldKind := fkCalculated;
    FieldName := 'MyFloat';
    DisplayFormat := '000000.00';
    DataSet := Table1;
  end;
  Table1.Open;
end;
0
 
LVL 1

Expert Comment

by:Alone
ID: 6944041
Try this:

type
  TMyForm = class(TForm)
    Table1: TTable;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    MyStringField: TStringField;
    MyFloatField: TFloatField;
  end;

{ TMyForm }

procedure TMyForm.Button1Click(Sender: TObject);
begin
  Table1.Close;
  MyStringField := TStringField.Create(Self);
  with MyStringField do
  begin
    FieldKind := fkCalculated;
    FieldName := 'MyString';
    Size := 100;
    DataSet := Table1;
  end;
  MyFloatField := TFloatField.Create(Self);
  with MyFloatField do
  begin
    FieldKind := fkCalculated;
    FieldName := 'MyFloat';
    DisplayFormat := '000000.00';
    DataSet := Table1;
  end;
  Table1.Open;
end;
0
 
LVL 1

Expert Comment

by:Alone
ID: 6944053
Sorry my message sent twice :-((
0
 
LVL 1

Expert Comment

by:pnh73
ID: 9003217
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Accept Answer from Alone

Please leave any comments here within the next seven days.
 
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
 
Paul (pnh73)
EE Cleanup Volunteer
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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
Both in life and business – not all partnerships are created equal. Spend 30 short minutes with us to learn:   • Key questions to ask when considering a partnership to accelerate your business into the cloud • Pitfalls and mistakes other partners…

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

22 Experts available now in Live!

Get 1:1 Help Now