CreateField

<< Click to Display Table of Contents >>

Navigation:  Apollo VCL Components > Apollo VCL Component Reference > TApolloTable > TApolloTable Methods >

CreateField

Declaration

procedure CreateField( sName, sType: String; iLen, iDec; Integer ):

Description

Defines a field to be included in a new table. A new file is created by first making a work area with CreateNew (which also defines the number of fields that the table will contain). Each field is then defined with CreateField, and the file is finally physically created by calling CreateExec.

 

The number of calls to CreateField must not exceed the defined number of fields passed as parameter iNumFields to function CreateNew.

Parameters

sName: The name of the field. Valid field names begin with a letter and may contain letters, numbers, and the underscore character. Field name maximum length is ten characters.

sType: The xBase drivers allow the following types:

 C for Character

N for Numeric

D for Date

F for Float

L for Logical

M for Memo

iLen: Field length. The maximum lengths for various types are:

 C 32733 (32k - 34)

N 19

D 8 (CCYYMMDD)

L 1

M 10 (default 10 to hold memo block reference)

 

Field lengths for D, L, and M types are automatically set to 8, 1, and 10 respectively.

The maximum length of a character field that can be extracted with the GetString functions is 255. Larger fields must be extracted with GetStringEx or ApolloGetRecord. Memo fields must be extracted with GetMemo.

iDec: The number of decimal positions if the field type is numeric. Note that the length of a numeric field that contains decimals includes the decimal point, a leading zero, and an optional sign. The minimum length for a numeric field that contains one decimal position is therefore 3 (unsigned) or 4 (signed). The maximum number of decimals allowed in DBF files is 16.

Delphi Example

procedure TForm1.Button1Click(Sender: TObject);

begin

 with ApTbl do 

 begin 

         if not CreateNew( 'c:\Apollo\testnew.dbf', SDEFOX, 5 ) then 

         begin  

                 ShowMessage( 'Create failed' ); 

                 Exit; 

         end; 

         CreateField( 'fchar', 'C', 25, 0 );

         CreateField( 'fnum', 'N', 10, 2 ); 

         CreateField( 'flog', 'L', 1, 0 ); 

         CreateField( 'fdate', 'D', 8, 0 ); 

         CreateField( 'fmemo', 'M', 10, 0 ); 

         if CreateExec then 

           ShowMessage( 'Create succeeded' )

         else 

                          ShowMessage( 'Create failed' ); 

 end; 

end;

C++Builder Example

void __fastcall TForm1::Button1Click(TObject *Sender)

{

if (!ApTbl->CreateNew( "c:\\Apollo\\testnew.dbf", SDEFOX, 5 )) 

 ShowMessage( "Create failed" ); 

 return; 

ApTbl->CreateField( "fchar", "C", 25, 0 );

ApTbl->CreateField( "fnum", "N", 10, 2 ); 

ApTbl->CreateField( "flog", "L", 1, 0 ); 

ApTbl->CreateField( "fdate", "D", 8, 0 ); 

ApTbl->CreateField( "fmemo", "M", 10, 0 ); 

if (ApTbl->CreateExec()) 

 ShowMessage( "Create succeeded" ); 

else 

 ShowMessage( "Create failed" ); 

}

See Also

CreateNew, CreateExec