我想callbackmethod
在它自己的线程中调用一个。将callbackMethod
作为接口实现。
我已经声明了一个线程,如下所示:
CustomfunctionCallbackThread = Class(TThread)
protected
procedure Execute; override;
private
var mCallId: String;
var mCallbackMethod: ICustomfunctionCallback;
var mParam: pCustomParam;
var mError: integer;
procedure callCallbackMethod;
public
procedure setData(callbackObject: pCustomfunctionCallbackObject);
end;
现在我将那个线程称为:
procedure classname.method(param :pCustomParam; callId: String; error: integer; callback: ICustomfunctionCallback);
var callbackObject: ^CustomfunctionCallbackObject;
var callbackThread: CustomfunctionCallbackThread;
begin
callbackObject.param:= param;
callbackObject.error:= error;
callbackObject.callId:= callId;
callbackObject.callbackMethod:= callback;
callbackThread:= CustomfunctionCallbackThread.Create(true);
callbackThread.setData(callbackObject);
callbackThread.FreeOnTerminate:= true;
callbackThread.Start;
end;
setData 函数如下所示:
procedure CustomfunctionCallbackThread.setData(callbackObject: pCustomfunctionCallbackObject);
begin
mCallId:=callbackObject.callId;
mParam:=callbackObject.param;
mError:=callbackObject.error;
mCallbackMethod:=callbackObject.callbackMethod;
end;
我的执行功能看起来像:
procedure CustomfunctionCallbackThread.Execute;
begin
mCallbackMethod.callCustomfunctionCallback(mParam, mCallId, mError);
end;
现在,回调方法(接口)如下所示:
procedure CustomfunctionCallback.callCustomfunctionCallback(param: pCustomParam; callId: String; error: integer);
var receivedCustomfunctionCallback: string;
begin
receivedCustomfunctionCallback:= 'CustomfunctionCallback received: Param - ' +
PAnsiChar(param^.getKey(0)) + ' | Value - ' + PAnsiChar(param^.getValue(0));
Form_PAis.Utf8Convert(receivedCustomfunctionCallback);
Dispose(param);
end;
该函数按应有的方式运行,但之后将自动退出调试模式。
如果它看起来像这样:
procedure CustomfunctionCallback.callCustomfunctionCallback(param: pCustomParam; callId: String; error: integer);
var receivedCustomfunctionCallback: string;
begin
receivedCustomfunctionCallback:= 'CustomfunctionCallback received: Param - ' +
PAnsiChar(param^.getKey(0)) + ' | Value - ' + PAnsiChar(param^.getValue(0));
Form_PAis.output.Append(receivedCustomfunctionCallback);
Dispose(param);
end;
它会崩溃(不退出)
Form_PAis.output.Append(receivedCustomfunctionCallback);
你有一个想法,如何解决这个问题?