[解决办法] 未装Delphi ,纯手工编写,可能有错。 回调函数定义如下,主程序,DLL都要定义 Type TDisplayCallback=procedure(const s:PChar);
DLL写法 function test(Conn :Pointer;const ID:Integer;DisplayCallback :TDisplayCallback):integer; stdcall; export; var AdoQuery:TAdoQuery; c :integer; begin AdoQuery :=TAdoQuery.Create(nil); AdoQuery.Connection :=TAdoConnection(Conn); result :=nil; Try AdoQuery.Connection :=AdoQuery; AdoQuery.SQL.text :='SELECT * FROM EMPLOYEE;'; c :=0; While AdoQuery.Eof do begin if AdoQuery.FieldByName('ID').asinteger=ID then begin Result :=PChar(AdoQuery.FieldByName('NAME').asstring); break; end; AdoQuery.Next; Inc(C); DisplayCallback(PChar(Format('%d%%',[Trunc((c/AdoQuery.recordcount)*100)]))); end; finally AdoQuery.free; end; end;
main写法
procedure FDisplayCallback(const s:PChar); begin Form1.Staturbar.panels[0].text :=s; end;