Product Documentation

VCL/CLX Developers Guide

Previous Topic

Next Topic

Define

Define() establishes specific data definitions. This involves defining columns/fields and creating the tables/files with optional indexes.

Below is the code for Define():

procedure TForm1.Define;

var

MustCreate : Boolean;

begin

// first try to open the table

MustCreate := False;

try

TabCustMast.Table := 'custmast';

TabCustMast.Active := true;

except

on ECtError do MustCreate := True;

end;

// if table does not exist, create it

if MustCreate then

begin

try

// create the table

TabCustMast.AddField('cm_custnum', CT_STRING, 5);

TabCustMast.AddField('cm_zip', CT_STRING, 10);

TabCustMast.AddField('cm_state', CT_STRING, 3);

TabCustMast.AddField('cm_rating', CT_STRING, 2);

TabCustMast.AddField('cm_name', CT_STRING, 48);

TabCustMast.AddField('cm_address', CT_STRING, 48);

TabCustMast.AddField('cm_city', CT_STRING, 48);

TabCustMast.Table := 'CUSTMAST';

TabCustMast.CreateTable;

// open the table just created

TabCustMast.Active := true;

except

on E : ECtError do Application.ShowException(E);

end;

end

else

begin

Check_Table_Mode(TabCustMast);

end;

end;

procedure TForm1.Check_Table_Mode(hTable : TCtTable);

begin

try

// And off the Transaction bit, IF it is set

if (hTable.CreateMode and CTCREATE_TRNLOG) = CTCREATE_TRNLOG then

begin

hTable.UpdateCreateMode(hTable.CreateMode xor CTCREATE_TRNLOG);

end;

except

on E : ECtError do Application.ShowException(E);

end;

end;

TOCIndex