Solved

How do I create a calculated field at RUNTIME?

Posted on 2002-04-15
4
1,085 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
Comment Utility
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
Comment Utility
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
Comment Utility
Sorry my message sent twice :-((
0
 
LVL 1

Expert Comment

by:pnh73
Comment Utility
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

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 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…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

771 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

14 Experts available now in Live!

Get 1:1 Help Now