我遇到了问题,我的 TThreadList 的内容似乎在我的线程中丢失了。
我在“PConnect”类中创建了以下变量:
var mCustomfunctionCallbackThread: CustomfunctionCallbackThread;
和一个像下面这样的全局变量:
var mCustomfunctionCallbackThreadList: TThreadList;
现在我在我的“PConnect”类中填充这个变量,如下所示:
function PConnect.callCustomfunction(plugin, method: PAnsiChar; param :CustomParam; callback: ICustomfunctionCallback; callId: PAnsiChar): integer;
var paramName: PAnsiChar;
var id: PAnsiChar;
var error: integer;
var callbackList: TList;
var customfunctionCallback : ^CustomfunctionCallbackObject;
begin
callbackList:= mCustomfunctionCallbackThreadList.LockList;
new (customfunctionCallback);
customfunctionCallback.callId:= id;
customfunctionCallback.callbackMethod:= callback;
callbackList.Add(customfunctionCallback);
mCustomfunctionCallbackThreadList.UnlockList;
exit(0);
end;
在收到回调后,将调用以下函数。此函数应将其他丢失的数据附加到 TThreadList 条目并在此之后启动一个线程:
procedure PConnect.customfunctionCallbackReceived(param :CustomParam; callId: PAnsiChar; error: integer);
var customfunctionCallbackList: TList;
var it: TListEnumerator;
var callbackObject: ^CustomfunctionCallbackObject;
begin
customfunctionCallbackList:= mCustomfunctionCallbackThreadList.LockList;
it:= customfunctionCallbackList.GetEnumerator;
while(it.MoveNext) do
begin
callbackObject:= it.GetCurrent;
if strcomp(callbackObject.callId,callId) = 0 then
begin
callbackObject.param:= param;
callbackObject.error:= error;
break;
end;
end;
mCustomfunctionCallbackThreadList.UnlockList;
mCustomfunctionCallbackThread.Start();
end;
Thread 的 Execute 方法应该获取 TThreadList 的内容并使用该参数调用函数。
procedure CustomfunctionCallbackThread.Execute;
var callback: ICustomfunctionCallback;
var customfunctionCallbackList: TList;
var it: TListEnumerator;
var callbackObject: ^CustomfunctionCallbackObject;
var param: CustomParam;
var callId: PAnsiChar;
var error: Integer;
begin
customfunctionCallbackList:= mCustomfunctionCallbackThreadList.LockList;
it:= customfunctionCallbackList.GetEnumerator;
while(it.MoveNext) do
begin
callbackObject:= it.GetCurrent;
if callbackObject.error <> NULL then
begin
callback:= callbackObject.callbackMethod;
param:= callbackObject.param;
error:= callbackObject.error;
callId:= callbackObject.callId;
callback.callCustomfunctionCallback(param, callId, error);
customfunctionCallbackList.Remove(callbackObject);
break;
end;
end;
mCustomfunctionCallbackThreadList.UnlockList;
end;
继承人的问题,以下变量刚刚得到垃圾或空指针:
param:= callbackObject.param;
error:= callbackObject.error;
callId:= callbackObject.callId;
我希望它已经足够描述了:)
我会很高兴得到一些帮助:)