Solved

Ttable question

Posted on 2004-09-28
7
385 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
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…

757 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

18 Experts available now in Live!

Get 1:1 Help Now