Solved

How do I create a calculated field at RUNTIME?

Posted on 2002-04-15
4
1,094 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 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
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…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

695 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