How to Convert Advantage API to Delphi

I am trying to translate a sample code in Delphi from Advantage Database documents, but it seems that it cannot correctly receive variable declarations starting with varType, and it also cannot define MAX_STR_LEN (constant, function, something else?).

Here is the code in the example:

 UNSIGNED32 DoDates( void )
 {  
      ADSHANDLE hTable;
      UNSIGNED16 usLength;
      UNSIGNED8 aucDOB[MAX_STR_LEN+1];
      ...
      usLength = MAX_STR_LEN+1
      AdsGetDate( hTable, "DOB", aucDOB, &usLength );
      ... 
 }

The Delphi code I tried is:

 procedure TForm1.fixARInvoiceEntryHeaderDates;
 var
      tableHandle:ADSHandle;
      aucDOB:pansichar;
      usLength:punsigned16;

 begin
      ...
      AdsGetDate(
      tableHandle,
      'inv_date',
      aucDOB,
      &usLength);
      ...
 end;
+4
source share
1 answer

MAX_STR_LEN 255 Advantage Client Engine , , DoDates. , , , ( , ).

, , ADS . ( 49 () , - 2 , .)

- :

// Reduced because of intended use. See text above, 2nd paragraph.
// If you're using this buffer for things other than dates,
// change to 255 as original code did.

const
  MAX_STR_LEN = 49;  

type
  TCharDateBuffer = array[0..MAX_STR_LEN + 1] of AnsiChar;

var
  DateBuffer: TCharDateBuffer;
  BuffSize: UNSIGNED16;       // From Ace.pas
  tableHandle: ADSHandle;     // From Ace.pas
begin
  // Your code to open the table and get the handle

  BuffSize := MAX_STR_LEN;
  AdsGetDate(tableHandle, 'DOB', DateBuffer, @BuffSize);
end;

Delphi, TDataSet descendant (, TAdsTable TAdsQuery). TField:

// Retrieve DOB as string
StrDOB := MyAdsTable.FieldByName('DOB').AsString;

// Get DOB as TDateTime
DOB := MyAdsTable.FieldByName('DOB').AsDateTime;

// Set date field to today
MyAdsTable.FieldByName('CHANGED').AsDateTime := Date;

`Advantage TDataSet ; Advantage, , , .

+5

All Articles