callbackmethod
独自のスレッドでa を呼び出したい。は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);
問題を解決する方法はありますか?