|
<< Click to Display Table of Contents >> Delphi Examples: DbiRegisterCallBack |
![]() ![]()
|
Example 1: Create a callback that handles the condition of a missing .MDX file for a dBASE file or a missing .CDX file for a FoxPro file:
//Function called by DbiRegisterCallBack
function myfunc(ecbType : CBType; iClientData : LongInt;
pCbInfo : pCBInputDesc): CBRType; stdcall;
const
READONLY = 'Read Only';
FAILOPEN = 'Fail Open'; //The default
OPENANDDETACH = 'Open and Detach';
var
counter : Integer;
begin
case ecbtype of
cbINPUTREQ: //It's a callback of cbINPUTREQ type
if (pcbInfo.eCbInputId = cbiMDXMIssing) then begin
for counter:=0 to (pcbInfo.iCount – 1) do
if (pcbInfo.acbEntry[counter].szKeyword = OPENANDDETACH) then begin
pcbInfo.iSelection := counter + 1;
pcbInfo.bSave := False;
break;
end;
end
else //if
ShowMessage('Unexpected eCbInputId');
else //case
ShowMessage('Unexpected ecbType')
end;
end;
//Register the callback and open the table
procedure TForm1.Button2Click(Sender: TObject);
var
cbinfo : CBInputDesc;
begin
Session.Open;
Check(DbiRegisterCallBack(
nil, //Cursor (Optional)
cbINPUTREQ, //Type of Callback
LongInt(0), //Pass-through client data
sizeof(CBInputDesc), //Callback buffer len
cbinfo, //Pointer to callback function
@myfunc //Call back fn being registered
));
Table1.Open;
//Unregister the callback
Check(DbiRegisterCallBack(nil, cbINPUTREQ, 0,
sizeof(CBInputDesc), nil , nil));
end;