Board index » delphi » Add Method not working? what have I done wrong?

Add Method not working? what have I done wrong?

You are leaving out the boolean value which indicates whether the field is
required or not.
..
Add('Company', ftString, 40, True); { This is a required field }
Add('Address2',ftString, 40, False); { This field is not a required field }
Quote
> I need to know how to create a new table from within Delphi.

> I have done what the book says to do and I keep getting compile error 87
> which stumps me.

> I have a TTable and a TDataSource component and

> Here is my code snipet:

> --------------

> with Form2.Table1 do
> begin
>   Active := False;
>   DatabaseName := ExtractFilePath(DBFileName);
>   TableName := ExtractFileName(DBFileName);
>   TableType := ttParadox;

>   with FieldDefs do
>   begin
>     Clear;    
>     Add('Company', ftString, 40);  <-- I get an Error 87: "," expected.
>                                ^  
>     ... other Adds here
>   end;
> end;

> --------------

> Delphi help defines the Add Method for TFieldDefs to be:
>   procedure Add(const Name: String; DataType: TFieldType; Size: Word);

> so why am I getting an error here?

> Please respond by e-mail as well as this newsgroup.

> ----------------------------------------------------------------------
> | Jerry & Ellen Davis  | If work were like my hobbies, then I would  |
> |                      | want to WORK all the time!                  |
> ----------------------------------------------------------------------

 

Re:Add Method not working? what have I done wrong?


I need to know how to create a new table from within Delphi.

I have done what the book says to do and I keep getting compile error 87
which stumps me.

I have a TTable and a TDataSource component and

Here is my code snipet:

--------------

with Form2.Table1 do
begin
  Active := False;
  DatabaseName := ExtractFilePath(DBFileName);
  TableName := ExtractFileName(DBFileName);
  TableType := ttParadox;

  with FieldDefs do
  begin
    Clear;    
    Add('Company', ftString, 40);  <-- I get an Error 87: "," expected.
                               ^  
    ... other Adds here
  end;
end;

--------------

Delphi help defines the Add Method for TFieldDefs to be:
  procedure Add(const Name: String; DataType: TFieldType; Size: Word);

so why am I getting an error here?

Please respond by e-mail as well as this newsgroup.

----------------------------------------------------------------------
| Jerry & Ellen Davis  | If work were like my hobbies, then I would  |
|                      | want to WORK all the time!                  |
----------------------------------------------------------------------

Re:Add Method not working? what have I done wrong?


Correct syntax for Add is:
procedure Add(const Name: String: DataType: TFieldType: Size: Word:
               Required: Boolean)
Add('Company', ftString, 40, false)

Nenad Petraek

Re:Add Method not working? what have I done wrong?


Correct syntax for Add is:
procedure Add(const Name: String: DataType: TFieldType: Size: Word:
               Required: Boolean)
Add('Company', ftString, 40, false)

Nenad Petraek

Re:Add Method not working? what have I done wrong?


Correct syntax for Add is:
procedure Add(const Name: String: DataType: TFieldType: Size: Word:
               Required: Boolean)
Add('Company', ftString, 40, false)

Nenad Petraek

Re:Add Method not working? what have I done wrong?


Correct syntax for Add is:
procedure Add(const Name: String: DataType: TFieldType: Size: Word:
               Required: Boolean)
Add('Company', ftString, 40, false)

Nenad Petraek

Re:Add Method not working? what have I done wrong?


Correct syntax for Add is:
procedure Add(const Name: String: DataType: TFieldType: Size: Word:
               Required: Boolean)
Add('Company', ftString, 40, false)

Nenad Petraek

Re:Add Method not working? what have I done wrong?


Correct syntax for Add is:
procedure Add(const Name: String: DataType: TFieldType: Size: Word:
               Required: Boolean)
Add('Company', ftString, 40, false)

Nenad Petraek

Re:Add Method not working? what have I done wrong?


This is not the right place, but I am using newsgroups for the first
time, dont know what have I done wrong, I thought that I send
nothing because of Netscape messages "Server 'mail' not found" or
similar. I'm shamed, so if anyone can remove my answers, please do.

Nenad

Re:Add Method not working? what have I done wrong?


I note that the inital question was "How do I create a database file
from scratch. The variations on the suggested useage of CreateTable do
not create the file. It compiles all right but when the code is run
the execution aborts with an invalid database or invalid alias error.
It appears it STILL expects a pre-existing file it recognizes as a
database file. I even tried FileClose(FileCreate('test.db')); and it
STILL wont create a database file and it still complains about an
invalid database file.

Re:Add Method not working? what have I done wrong?


function TFrameForm.CreateResultstable( cFileName: string ): boolean;
{
  TFieldType = (ftUnknown, ftString, ftSmallint, ftInteger, ftWord,
ftBoolean,
                ftFloat, ftCurrency, ftBCD, ftDate, ftTime, ftDateTime,
ftBytes,
                ftVarBytes, ftBlob, ftMemo, ftGraphic);
Quote
}

begin
  MessageForm.TextLabel.Caption := 'Creating New Table: ' + cFileName;
  MessageForm.Show;
  with TempTable do begin
    Active := False;
    DatabaseName := gcResultsDatabaseName;
    TableName := cFileName;
    TableType := ttParadox;
    with FieldDefs do begin
      Clear;
      Add('DOCNO',   ftString,   11, False);
      Add('FFRAME',  ftSmallInt,  0, False);
      Add('LFRAME',  ftSmallInt,  0, False);
      Add('PAGES',   ftSmallInt,  0, False);
      Add('DOCDATE', ftDate,      0, False);
      Add('TITLE',   ftMemo,     50, False);
    end;
    with IndexDefs do begin
      Clear;
      Add('DOCNO',   'DOCNO', [ixPrimary]);
      Add('DOCDATE', 'DOCDATE', []);
    end;
    CreateTable;
  end; {with}
  Delay( 1 );
  MessageForm.Hide
end; {CreateResultstable}

HTH
Glen Mann
gm...@haven.ios.com

Quote
Garry Freemyer (ga...@athenon.com) wrote:

: I note that the inital question was "How do I create a database file
: from scratch. The variations on the suggested useage of CreateTable do
: not create the file. It compiles all right but when the code is run
: the execution aborts with an invalid database or invalid alias error.
: It appears it STILL expects a pre-existing file it recognizes as a
: database file. I even tried FileClose(FileCreate('test.db')); and it
: STILL wont create a database file and it still complains about an
: invalid database file

Re:Add Method not working? what have I done wrong?


Quote
Garry Freemyer wrote:

> I note that the inital question was "How do I create a database file
> from scratch. The variations on the suggested useage of CreateTable do
> not create the file. It compiles all right but when the code is run
> the execution aborts with an invalid database or invalid alias error.
> It appears it STILL expects a pre-existing file it recognizes as a
> database file. I even tried FileClose(FileCreate('test.db')); and it
> STILL wont create a database file and it still complains about an
> invalid database file.

Try something like this:

procedure CreateTable;
var
  table: TTable;
begin
  table := TTable.Create(nil);
  with table do
  begin

    { Creating : AutoDB --> TEST.DB }
    DataBaseName := 'AutoDB'; {An alias or path}
    TableName := 'TEST.DB';
    TableType := ttParadox;
    with FieldDefs do
    begin
      Clear;
      Add('Field1', ftString, 12, False);
      Add('Field2', ftString, 12, False);
      Add('Field3', ftString, 10, False);
      Add('Nr', ftInteger, 0, False);
      Add('BoolField', ftBoolean, 0, False);
      Add('Date', ftDate, 0, False);
    end; { FieldDefs }
    with IndexDefs do
    begin
      Clear;
      Add('', 'Field1;Fiel2', [ixPrimary, ixUnique]);
      Add('RptInd', 'Field2;Field1', [ixCaseInsensitive]);
      Add('indNr', 'Nr', [ixCaseInsensitive]);
    end; { IndexDefs }
    CreateTable;
  end;
  Table.free;
end;

I've got a program that does this automaticly. It's down loaded from The
Net and it's called datamake.zip

Other Threads