Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How do I create a calculated field at RUNTIME?

Posted on 2002-04-15
4
Medium Priority
?
1,096 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 1

Accepted Solution

by:
Alone earned 400 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

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…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

715 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