Solved

Ttable question

Posted on 2004-09-28
7
389 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
[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
  • 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 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

Suggested Solutions

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

730 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