All LayGO API function names and argument sequences are identical to those documented in the C language API. For instance, the code to open a CID which might be written in C as:
LCid cid;
cid = lgo_Open("PHYS0");
if (cid < 0)
{
PostOpenError(cid);
}
else
{
ConnectCid(cid);
}
translates directly into the following Pascal code in Delphi 4:
cid: LCid;
cid := lgo_Open('PHYS0');
if cid < 0 then
PostOpenError(cid)
else
ConnectCid(cid);
For functions which take C pointer types such as LDataBuffer or
LCtlBuffer, substitute the address of an array of
Byte. The C code to read data:
unsigned char buffer[1024];
LResult result;
result = lgo_Read(cid, buffer, 1024);
if (result > 0)
{
ProcessData(buffer, result);
}
else if (result == lgo_ERROR_EVENT_WAITING)
{
ReadEvent();
}
becomes the Delphi 4 code:
buffer: array [0..1023] of Byte;
result: LResult;
result := lgo_Read(cid, @buffer, 1024);
if result > 0 then
ProcessData(@buffer, result)
else if result = ERROR_EVENT_WAITING then
ReadEvent();
The argument can also be a pointer to dynamically allocated memory:
buffer: ^Byte; result: LResult; buffer := AllocMem(1024); result := lgo_Read(cid, buffer, 1024);
Where a NULL pointer would be used in C, substitute the manifest
constant nil:
LResult result; result = lgo_ConnectRequest(cid, NULL, 0);
becomes
result: LResult; result = lgo_ConnectRequest(cid, nil, 0);
All the other C integral types which are used as function arguments or return values are mapped to the proper Pascal types in Laygo.pas.