Solved

Ttable question

Posted on 2004-09-28
7
387 Views
Last Modified: 2010-04-05
I placed a Ttable component in FORM1, then double click on the Ttable component. There is a  FORM1.Table1 that will pop-up, then i tried to create a new field.

The above procedure is done manually, how about if i will make that procedure above dynamic like having a source code to create a new field from the FORM1.table1.

How will i do that?
0
Comment
Question by:girlswants_me
  • 3
  • 2
  • 2
7 Comments
 
LVL 1

Expert Comment

by:SJohnson
ID: 12176937
A TTable is supposed to be linked to a database table.  It's not supposed to be just used as a stand alone component.   When you connect it to a TTable, it will automatically populate itself with the field values.

If you want to add a new calculated or lookup field to the Ttable, you can do that with the FieldDefs property (look in the help for FieldsDefs.Add).  It's quite easy to do.

Stu.
0
 

Author Comment

by:girlswants_me
ID: 12177262
Hi Sjohnson,

Yes i can add field with my TTABLE even though without having a database table linked to it. Try this.
1. Double click on any Ttable component and a tool window will popup
2. Right click inside the tool window (Form1.Table1) and select "New Field..."
3. Now, a NEW FIELD dialog will come out. Place any values on the fields under NEW FIELD dialog.
4. You will now have a field inside the Form1.Table1 tool window.

Does FieldsDefs.add() method is the same as above?
0
 

Author Comment

by:girlswants_me
ID: 12177273
And if FieldsDefs.add() is the same as what i did on the procedures, how can i assign a code inside the event OnGetTex(Sender: TField; var Text: String;  DisplayText: Boolean) ?

procedure TForm1.CurrencyGetText(Sender: TField; var Text: String;
  DisplayText: Boolean);
begin
 Text:='The value is ' + Sender.asstring;
end;
0
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
LVL 1

Expert Comment

by:SJohnson
ID: 12177284
I'm just on my way home now, so I'll look at this more closely when I get home.

When you add the field definitions manually (through the IDE), can you actually populate those fields with data?  Do you set a TableName as well?  I've just never done it like this before (I guess I can't see why it won't work).

Stuart.
0
 
LVL 12

Expert Comment

by:esoftbg
ID: 12177409
Note:
  AddFieldDef is only valid in the context of creating field definitions for a table to be created with a subsequent call to the CreateTable or CreateDataSet method. It cannot be used to add fields to an already-existing table.
0
 
LVL 12

Accepted Solution

by:
esoftbg earned 125 total points
ID: 12177496
procedure TForm1.SpeedButtonCreateParadoxTableClick(Sender: TObject);
var
  S:      string;
begin
  S := ExtractFilePath(Application.ExeName) + 'SINGERS.DB';
  with Table1 do
  begin
    Active := False;
    DatabaseName := '';
    TableType := ttParadox;
    TableName := 'SINGERS';

    try
      { Don't overwrite an existing table }

      if not Table1.Exists then
      begin
        { The Table component must not be active }
        { First, describe the type of table and give }
        { it a name }
        { Next, describe the fields in the table }
        with FieldDefs do
        begin
          Clear;
          with AddFieldDef do
          begin
            Name := 'ID';
            DataType := ftAutoInc;
            Required := True;
          end;
          with AddFieldDef do
          begin
            Name := 'ALL_NAMES';
            DataType := ftString;
            Size := 32;
          end;
        end;
        { Next, describe any indexes }
        with IndexDefs do
        begin
          Clear;
          { The 1st index has no name because it is
          { a Paradox primary key }
          with AddIndexDef do
          begin
            Name := 'Primary_Key';
            Fields := 'ID';
            Options := [ixPrimary];
          end;
          with AddIndexDef do
          begin
            Name := 'ALL_NAMES_Indx';
            Fields := 'ALL_NAMES';
            Options := [ixCaseInsensitive];
          end;
        end;
        { Call the CreateTable method to create the table }
        CreateTable;
      end;
    finally
      Table1.Active := True;
    end;
  end;
end;
0
 

Author Comment

by:girlswants_me
ID: 12177758
Thanks a lot.
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Newbie Thread Programming 1 151
error 1.1 400 Bad request idhttp delphi 18 86
Intraweb download file link ? 1 132
Delphi inherited method 6 68
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…
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 Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

776 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