I've a dll and a library file to use the Dll. In a file
TOnPortStatusChanged = procedure (cardNo:integer; portNo:integer; newPortStatus:byte); stdcall;
TOnPortDataReady = procedure (cardNo:integer; portNo:integer; dataBuff:PByteArray; buffLen:integer); stdcall;
T_API_INIT_PARAMS = record
OnPortStatusChanged :TOnPortStatusChanged;
OnPortDataReady :TOnPortDataReady ;
end;
P_API_INIT_PARAMS = ^T_API_INIT_PARAMS ;
//....
//...
var
PR_Init: function (initParams: P_API_INIT_PARAMS):integer; stdcall;
when I want to use this function in my program, my code :
procedure PortStatusChanged(cardNo: integer; portNo: integer; newPortStatus: byte); stdcall;
begin
//...
end;
procedure TMainThread.CheckDevices;
var
vCount: integer;
initParams: T_API_INIT_PARAMS;
begin
initParams.OnPortStatusChanged := PortStatusChanged;
initParams.OnPortDataReady := nil;
vCount := PR_Init(@initParams);
That works fine. But I want to use PortStatusChanged procedure in TMainThread class. So I write the procedure in TMainThread class and change TOnPortStatusChanged type like that:
TOnPortStatusChanged = procedure (cardNo:integer; portNo:integer; newPortStatus:byte) of object; stdcall;
When I run my program in this way; PortStatusChanged works correct at the first time, but the second it gives an access violation error.
Where am I making mistake?