Using Apollo COM with Delphi

<< Click to Display Table of Contents >>

Navigation:  Apollo COM > Getting Started >

Using Apollo COM with Delphi

 

The following beta notes are provided to get users started using Apollo COM. The syntax used in these examples is Delphi.

 

Delphi syntax:

//-------------------------------------------------------

procedure TForm2.FormCreate(Sender: TObject);

var

oQuery, oTable : Variant;

sLName, sFName, sPath : String;

begin

//CreateComObject(CLASS_Table);

 oTable  := CreateOleObject('ApolloCOM9.Table');

 oQuery := CreateOleObject('ApolloCOM9.Query');

 

sPath := trim(Edit1.Text);

oQuery.AccessMethod := 'amServer'; // or 'amLocal'

oQuery.User    := 'SYSDBA';

oQuery.Password  := 'masterkey';

oQuery.Host   := '127.0.0.1';

oQuery.Port   := 8121;

oQuery.DatabaseName := 'DATA';

 

oQuery.ClearTables;

oQuery.SetTables ('TEST.DBF', 'TEST', 'ttSXFOX', '', FALSE);

 

oTable.AccessMethod  := 'amServer';

oTable.DatabaseName  := c:\Apollo\9.9\x86\Data\';

oTable.User   := 'SYSDBA';

oTable.Password  := 'masterkey';

oTable.Host   := '127.0.0.1';

oTable.TableName  := 'TEST.DBF';

 

end;

 

//-------------------------------------------------------

procedure TForm2.RunSQL;

begin

oQuery.SQL := 'DELETE FROM test WHERE STATE Like "%MA%" ';

 

// execute the SQL statement

oQuery.ExecSQL;

Label1.Caption := oQuery.ErrorMsg;

oQuery.Close;

 

end;

 

//--------------------------------------

procedure TForm2.CloseTable;

begin

oTable.Close;

end;

 

//-------------------------------------------------------

procedure TForm2.Move;

begin

// move to the next record

oTable.Skip(1);

// Show the current record number

Label1.Caption := IntToStr( oTable.RecNo );

end;

 

//-------------------------------------------------------

procedure TForm2.ReadData;

var

FName, LName: string;

Age : integer;

begin

Memo1.Clear;

oTable.GoTop;

While not oTable.Eof do

Begin

 // Get field data

 FName := oTable.GetString('FIRST');

 LName := oTable.GetString('LAST');

 Age  := oTable.GetString('AGE');

 Memo1.Lines.Add( FName +' '+ LName +' '+ IntToStr(Age) );

 // Move to the next record

 oTable.Skip(1);

end;

end;

//-------------------------------------------------------

procedure TForm2.RunSQL2;

var

i: integer;

begin

 

// issue a new SQL statement

oQuery.SQL := 'SELECT * FROM TEST';

oQuery.Open;

 

mList.Clear;

i := 0;

// Run through the result set until not end of file

while ( not oQuery.Eof ) do

begin

 // For legibility, store data from the query

 // to temporary variables

 sFName := oQuery.FieldByName('First');

 sLName := oQuery.FieldByName('Last');

 label1.caption := sFName+' '+sLName;

 

 mList.Items.Add('');

 mList.Items.Strings[i] := label1.Caption;

 inc(i);

 

 oQuery.Next;

 

end;

// oQuery.Close;

end;

 

// Example on how to pass a pointer to the Automation server

// an array of Variant must be created first

//-------------------------------------------------------

procedure TForm2.PassPointer;

var

p : Pointer;

i : Integer;

v : OleVariant;

s : String;

begin

TButton(Sender).Enabled := FALSE;

s := #0;

i := Length(s);

V := VarArrayCreate([0, i-1], varByte);

P := VarArrayLock(V);

 

Try

Move(s[1], p^, i);

Finally

VarArrayUnlock(V);

End;

i := oTable.SysProp( SDE_SP_GETINDEXCOUNT, V );

 

Label1.Caption := IntToStr(i);

TButton(Sender).Enabled := TRUE;

 

end;

//-------------------------------------------------------

procedure TForm2.CreatIndex;

var

i : Integer;

begin

// open a table and create an index

oTable.Close;

oTable.DatabaseName  := 'c:\data\';

oTable.TableName  := 'TEST.DBF';

ooTable.Exclusive   := True;

 

oTable.Open;

i := oTable.IndexTag( '', 'Salary', 'SALARY',

     IDX_UNIQUE, FALSE, '.not. Deleted()');

Label1.Caption := IntToStr(i);

oTable.Close;

end;