?
Solved

Ttable question

Posted on 2004-09-28
7
Medium Priority
?
394 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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 500 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses
Course of the Month14 days, 13 hours left to enroll

839 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