Board index » delphi » Problem with TTable.CreateTable.

Problem with TTable.CreateTable.

Hello,

I'm stuck here.

When I call TTable.CreateTable nothing happens. I made sure I
initialized the needed properties DatabaseName, TableName, FieldDefs
and IndexDefs with apropriate values. I even tried various
combinations of Exclusive and Active before calling CreateTable, but
still when I call CreateTable I don't get a new table. I don't even
get an errormessage! There's probably something very obvious I'm
overlooking but I wouldn't know what.

Could anyone of you enlighten me with some of the needed knowledge for
this to work?

Thanks!

Greetings HdV
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The road to wisdom?
Well, it's plain and simple to express:
Err and err and err again,
but less and less and less.
(Piet Hein)

HdV aka J.A.deVr...@lr.tudelft.nl
Delft University of Technology
Faculty of AeroSpace Engineering

 

Re:Problem with TTable.CreateTable.


Linguist

Quote
> Hello,

> I'm stuck here.

> When I call TTable.CreateTable nothing happens. I made sure I
> initialized the needed properties DatabaseName, TableName, FieldDefs
> and IndexDefs with apropriate values. I even tried various
> combinations of Exclusive and Active before calling CreateTable, but
> still when I call CreateTable I don't get a new table. I don't even
> get an errormessage! There's probably something very obvious I'm
> overlooking but I wouldn't know what.

> Could anyone of you enlighten me with some of the needed knowledge for

> this to work?

> Thanks!

Post your code so that everybody could help you debug.

Re:Problem with TTable.CreateTable.


On Wed, 21 Jan 1998 19:39:45 +0800, {*word*104}Cying <cy...@m2.dj.net.tw>
wrote:

Quote
>Linguist ?g1D?G

>> Hello,

>> I'm stuck here.

>> When I call TTable.CreateTable nothing happens. I made sure I
>> initialized the needed properties DatabaseName, TableName, FieldDefs
>> and IndexDefs with apropriate values. I even tried various
>> combinations of Exclusive and Active before calling CreateTable, but
>> still when I call CreateTable I don't get a new table. I don't even
>> get an errormessage! There's probably something very obvious I'm
>> overlooking but I wouldn't know what.

>> Could anyone of you enlighten me with some of the needed knowledge for

>> this to work?

>> Thanks!

>Post your code so that everybody could help you debug.

Good idea indeed!

Here are two versions I tried:

//This creates no databasefiles at all.
procedure TfrmMain.CreateNewTable(stableName: String);
var
  sOldDatabaseName, sOldTableName: String;
  lWasActive, lWasExclusive: Boolean;
begin
  try
    sOldDatabaseName := tblContents.DatabaseName;
    sOldTableName := tblContents.TableName;
    lWasActive := tblContents.Active;
    lWasExclusive := tblContents.Exclusive;
    tblContents.Active := False;
    tblContents.DatabaseName := sSaveAsDir;
    tblContents.TableName := stableName;
    tblContents.TableType := ttParadox;
    with tblContents.FieldDefs do begin
      Clear;
      Add('Archive', ftString, 35, False);
      Add('Product', ftString, 35, False);
      Add('Type', ftString, 20, False);
      Add('D1', ftBoolean, 0, False);
      Add('D2', ftBoolean, 0, False);
      Add('D3', ftBoolean, 0, False);
      Add('CB', ftBoolean, 0, False);
      Add('Status', ftString, 20, False);
      Add('Source', ftBoolean, 0, False);
      Add('Origin', ftString, 35, False);
      Add('Guide', ftMemo, 1, False);
      Add('Comments', ftMemo, 1, False);
      Add('OrigImg', ftGraphic, 0, False);
      Add('CurrImg', ftGraphic, 0, False);
    end; //end with
    with tblContents.IndexDefs do begin
      Clear;
      Add('', 'Archive; Product; Type', [ixPrimary, ixUnique,
ixCaseInsensitive]);
      Add('idx_Archive_Up', 'Archive', [ixCaseInsensitive]);
      Add('idx_Archive_Down', 'Archive', [ixCaseInsensitive,
ixDescending]);
      Add('idx_Product_Up', 'Product', [ixCaseInsensitive]);
      Add('idx_Product_Down', 'Product', [ixCaseInsensitive,
ixDescending]);
      Add('idx_Type_Up', 'Type', [ixCaseInsensitive]);
      Add('idx_Type_Down', 'Type', [ixCaseInsensitive, ixDescending]);
      Add('idx_Status_Up', 'Status', [ixCaseInsensitive]);
      Add('idx_Status_Down', 'Status', [ixCaseInsensitive,
ixDescending]);
      Add('idx_Origin_Up', 'Origin', [ixCaseInsensitive]);
      Add('idx_Origin_Down', 'Origin', [ixCaseInsensitive,
ixDescending]);
    end; //end with
    tblContents.CreateTable;
  //end try
  finally
    try
      tblContents.Active := True;
    //end try
    except
      MessageDlg('Sorry, couldn''t create the new table for you.',
mtError, [mbOK], 0);
      tblContents.Active := False;
      tblContents.DatabaseName := sOldDatabaseName;
      tblContents.TableName := sOldTableName;
      tblContents.Exclusive := lWasExclusive;
      tblContents.Active := lWasActive;
    end; //end except
    //Need to add some clean-up code in case some, but not all, files
were created.
  end; //end finally
end;

//This creates no .db file.
//It does produce some memo- and indexfiles, but not all.
procedure TfrmMain.CreateNewTable(stableName: String);
var
  sOldDatabaseName, sOldTableName: String;
  lWasActive, lWasExclusive: Boolean;
  tblTemp: TTable;
begin
  try
    sOldDatabaseName := tblContents.DatabaseName;
    sOldTableName := tblContents.TableName;
    lWasActive := tblContents.Active;
    lWasExclusive := tblContents.Exclusive;
    tblContents.FieldDefs.Update;
    tblContents.IndexDefs.Update;
    tblContents.Active := False;
    tblTemp := TTable.Create(nil);
    tblTemp.DatabaseName := tblContents.DatabaseName;
    tblTemp.TableName := stableName;
    tblTemp.TableType := tblContents.TableType;
    tblTemp.FieldDefs.Assign(tblContents.FieldDefs);
    tblTemp.IndexDefs.Assign(tblContents.IndexDefs);
    tblTemp.CreateTable ;
  //end try
  finally
    try
      tblContents.DatabaseName := tblTemp.DatabaseName;
      tblContents.TableName := tblTemp.TableName;
      tblContents.Active := True;
    //end try
    except
      MessageDlg('Sorry, couldn''t create the new table for you.',
mtError, [mbOK], 0);
      tblContents.Active := False;
      tblContents.DatabaseName := sOldDatabaseName;
      tblContents.TableName := sOldTableName;
      tblContents.Exclusive := lWasExclusive;
      tblContents.Active := lWasActive;
    end; //end except
    tblTemp.Free;
    //Need to add some clean-up code in case some, but not all, files
were created.
  end; //end finally
end;

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The road to wisdom?
Well, it's plain and simple to express:
Err and err and err again,
but less and less and less.
(Piet Hein)

HdV aka J.A.deVr...@lr.tudelft.nl
Delft University of Technology
Faculty of AeroSpace Engineering

Other Threads