I am trying to translate sample code to Delphi from the Advantage Database docs, but can't seem to get the variable declarations correct, starting with the varType and also cannot figure out MAX_STR_LEN (constant,function,something else?).
Here is the code in the sample:
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've tried is:
procedure TForm1.fixARInvoiceEntryHeaderDates;
var
tableHandle:ADSHandle;
aucDOB:pansichar;
usLength:punsigned16;
begin
...
AdsGetDate(
tableHandle,
'inv_date',
aucDOB,
&usLength);
...
end;
MAX_STR_LEN
is defined as being 255 in the Advantage Client Engine Sample Code help topic, at the very top of the page you quoted from for theDoDates
sample. They declare it that way because they use it all over the sample code, so it's large enough to be used to return various types of data (string content of character, date, and other types).If you're only going to use the buffer specifically for retrieving dates, you can use a much smaller buffer size, as none of the ADS date types or formats is anywhere near that long. (I've used a buffer size of 49 single-byte characters (bytes) in my sample below, which is still at least 2x the size it needs to be.)
Something like this should work:
It's much easier from Delphi, though, if you use their
TDataSet descendant
components (for instance,TAdsTable
orTAdsQuery
). You can then use normalTField
properties:The `Advantage TDataSet components are available from their Product Downloads page; click the link for the version of Advantage you're using, and you'll find a link to the components on the page that for that version.