[英]How convert Advantage API Sample C Code To Delphi
我試圖從Advantage Database文檔中將示例代碼轉換為Delphi,但似乎無法使變量聲明正確,從varType開始,也無法找出MAX_STR_LEN(常量,函數,還有其他?)。
以下是示例中的代碼:
UNSIGNED32 DoDates( void )
{
ADSHANDLE hTable;
UNSIGNED16 usLength;
UNSIGNED8 aucDOB[MAX_STR_LEN+1];
...
usLength = MAX_STR_LEN+1
AdsGetDate( hTable, "DOB", aucDOB, &usLength );
...
}
我試過的Delphi代碼是:
procedure TForm1.fixARInvoiceEntryHeaderDates;
var
tableHandle:ADSHandle;
aucDOB:pansichar;
usLength:punsigned16;
begin
...
AdsGetDate(
tableHandle,
'inv_date',
aucDOB,
&usLength);
...
end;
MAX_STR_LEN
在Advantage Client Engine 示例代碼幫助主題中定義為255,位於您為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;
但是,如果你使用他們的TDataSet descendant
組件(例如, TAdsTable
或TAdsQuery
),Delphi會容易得多。 然后,您可以使用普通的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版本的鏈接,您將找到該頁面上組件的鏈接。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.