我的问题是:我有一个VCL表单应用程序,以及一个包含TThread
实现的DLL。在这个Thread中,我有一些方法需要使用主窗体中的一些VCL组件,但我现在TThread.Synchronize()
在DLL内部没有工作,因为它给了另一个ThreadID到它,为了解决这个问题,我在DLL中创建了一个从VCL应用程序接收MainThreadID的方法,并将给定的方法设置为自己的DLL ID,但是,它也没有工作。有人能指出我做错了吗?
顺便说一句,我尝试使用间隔= 1到CheckSynchronize()
的时间,但它无论如何都是死路一条。
--->以下是代码的相关部分:
VCL单位
procedure TfrmUpdater.FormCreate(Sender: TObject);
var
IniFile: TIniFile;
begin
DllHandle := LoadLibrary('libthread.dll');
tmrSync.Enabled := True;
if DllHandle <> 0 then
begin
@DllThreadProc := GetProcAddress(DllHandle, 'SetDllThread');
@ConfigProc := GetProcAddress(DllHandle, 'Config');
@VclProc := GetProcAddress(DllHandle, 'VCL');
@UpdateProc := GetProcAddress(DllHandle, 'Update');
end;
DllThreadProc(MainThreadID);
// Set the VCL Components to use as reference inside the DLL
VclProc(btnStartGame, pbCurrent, pbOverall, lblCurrent, lblPercent);
end;
DLL代码
// This, doesn't update the CLbl that has been set as lblCurrent
// Note: this method is called INSIDE the DLL, and has to be like this!
procedure TUpdateThread.UpdateStatusLabel;
begin
CLbl.Caption := STemp;
Application.ProcessMessages;
end;
// The code below are SOME of the functions that the DLL is exporting to my application
procedure SetDllThread(TID: Cardinal); export;
begin
MainThreadID := TID;
end;
procedure VCL(playBtn: TImage; currentPBar, totalPBar: TALProgressBar; CurrLbl, ProgressLbl: TLabel); export;
begin
Btn := playBtn;
CBar := currentPBar;
TBar := totalPBar;
CLbl := CurrLbl;
TLbl := ProgressLbl;
end;