Board index » delphi » ttable.createtable--what am I doing wrong?

ttable.createtable--what am I doing wrong?

I dropped a ttable component named treelist onto a report and defined its
fields in the fielddefs property in the object inspector.  It's tablename
property is called treelist.db and its database property is set to wcdata,
the alias of my data files.  I want this table to be created if it does not
already exist when file/print is selected on the main form.  The code I use
to do this looks like this:

       With repgenealogy do
         begin
          if not treelist.Exists
           then
             begin
               treelist.Active := false;
               treelist.CreateTable;

             end;

When the program tries to execute the createTable command I get an
Edatabaseerror with message:  treelist: field 'page, element, generation'
not found.

These fields are defined as integer fields in my fielddefs property.  I have
used similar code to create tables successfully elsewhere in my app.  I
don't have a clue why this isn't working.  Thanks in advance for any help.

Helga Gray

 

Re:ttable.createtable--what am I doing wrong?


Hi Helga!
This is the complete code to create TTable at run-time

  procedure CreateTmpTable;
  begin
    with CompTmp do
    begin
      Active := False;
      DatabaseName := 'QWERTY';
      TableName := 'Tmp';
      TableType := ttDefault;
      with FieldDefs do
      begin
        Clear;
        Add('ID', ftInteger, 0, False);
        Add('GroupID', ftInteger, 0, False);
        Add('Name', ftString, 60, False);
        Add('TotalSum', ftFloat, 0, False);
      end;
      with IndexDefs do
      begin
        Clear;
        Add('idx_ID', 'ID', [ixPrimary, ixUnique]);
      end;
      CreateTable;
    end;
  end;

Other Threads