Z
zytzjx
Unregistered / Unconfirmed
GUEST, unregistred user!
这是什么什么问题呀,在多线程中,我用了Synchronize就不行了,就不像多线程了,我主界面上所有的动作都不做了,就像是在一个大循环一样,我要是把Synchronize这个不要就可以了,不过现在我要用这个,因为,有一个对话框要用用了,所以就必有这个Synchronize才不会出错的。怎么办法呀?
procedure TThTest.Execute;
begin
{ Place thread code here }
TestPCBA;
//Synchronize加上这个就不出错,但就不像多线程的,不加就出错
end;
function TThTest.MsgDlgShow(Value: string): Integer;
begin
with TStatusDlg.Create(nil)do
//因为这儿有一个DLG
try
MsgStr := Value;
result := ShowModal;
finally
Free;
end;
end;
procedure TThTest.TestPCBA;
begin
Stream := TFileStream.Create(FileNamePCBA, fmOpenRead);
try
with Streamdo
begin
Read(iCount, Sizeof(Integer));
while(Position < Size)do
begin
//if then
break;
if(GetKeyState(VK_ESCAPE) < 0) then
break;
if Terminated then
break;
Read(bCommand, Sizeof(BYTE));
SendMessage(MainForm.Handle, WM_TESTTHTOMAIN, 3, 0);
case bCommand of
$FF:
begin
MainForm.bTestItem := $FF;
Read(iCount, Sizeof(integer));
SetString(TstHeader, nil, iCount);
Read(Pointer(TstHeader)^, iCount);
MainForm.pnlStatus.Caption := '正在测试:' + TstHeader;
//ShowMessage(Header);
end;
$FE:
begin
MainForm.bTestItem := $FE;
Read(bCommand, Sizeof(BYTE));
Read(iCount, Sizeof(integer));
SetString(Header, nil, iCount);
Read(Pointer(Header)^, iCount);
if (bCommand = 0) then
begin
Synchronize(MsgDlgShow(Header));
//if (MsgDlgShow(Header) = mrOK) then
//else
DataDoc.bTestOK := FALSE;
end;
end;
$08: //$08得到RTC并写入
begin
end;
$07: //如果为$07,再后面的一个数据是要从外面读入,如果是为104,就是读入104的内容,如果是105就是读105的内容
begin
end;
$06: //$06为写
begin
end;
$04: //$04,则为Warm or cold start
begin
end;
$03://$03为读,后面WORD是要读出的为正确的内容,
begin
end;
$02: //$02为读,后面的数据是104或105的内容,也就是读出来要比较的,这个时候,加上正负误差的。
begin
end;
else
begin
MainForm.bTestItem := 0;
break;
end;
end;
end;
end;
finally
SendMessage(MainForm.Handle, WM_TESTTHTOMAIN, 4, 0);
if DataDoc.bTestOK then
begin
SendMessage(MainForm.Handle, WM_TESTTHTOMAIN, 5, 2);
end
else
begin
SendMessage(MainForm.Handle, WM_TESTTHTOMAIN, 5, 3);
end;
Stream.Free;
end;
end;
procedure TThTest.Execute;
begin
{ Place thread code here }
TestPCBA;
//Synchronize加上这个就不出错,但就不像多线程的,不加就出错
end;
function TThTest.MsgDlgShow(Value: string): Integer;
begin
with TStatusDlg.Create(nil)do
//因为这儿有一个DLG
try
MsgStr := Value;
result := ShowModal;
finally
Free;
end;
end;
procedure TThTest.TestPCBA;
begin
Stream := TFileStream.Create(FileNamePCBA, fmOpenRead);
try
with Streamdo
begin
Read(iCount, Sizeof(Integer));
while(Position < Size)do
begin
//if then
break;
if(GetKeyState(VK_ESCAPE) < 0) then
break;
if Terminated then
break;
Read(bCommand, Sizeof(BYTE));
SendMessage(MainForm.Handle, WM_TESTTHTOMAIN, 3, 0);
case bCommand of
$FF:
begin
MainForm.bTestItem := $FF;
Read(iCount, Sizeof(integer));
SetString(TstHeader, nil, iCount);
Read(Pointer(TstHeader)^, iCount);
MainForm.pnlStatus.Caption := '正在测试:' + TstHeader;
//ShowMessage(Header);
end;
$FE:
begin
MainForm.bTestItem := $FE;
Read(bCommand, Sizeof(BYTE));
Read(iCount, Sizeof(integer));
SetString(Header, nil, iCount);
Read(Pointer(Header)^, iCount);
if (bCommand = 0) then
begin
Synchronize(MsgDlgShow(Header));
//if (MsgDlgShow(Header) = mrOK) then
//else
DataDoc.bTestOK := FALSE;
end;
end;
$08: //$08得到RTC并写入
begin
end;
$07: //如果为$07,再后面的一个数据是要从外面读入,如果是为104,就是读入104的内容,如果是105就是读105的内容
begin
end;
$06: //$06为写
begin
end;
$04: //$04,则为Warm or cold start
begin
end;
$03://$03为读,后面WORD是要读出的为正确的内容,
begin
end;
$02: //$02为读,后面的数据是104或105的内容,也就是读出来要比较的,这个时候,加上正负误差的。
begin
end;
else
begin
MainForm.bTestItem := 0;
break;
end;
end;
end;
end;
finally
SendMessage(MainForm.Handle, WM_TESTTHTOMAIN, 4, 0);
if DataDoc.bTestOK then
begin
SendMessage(MainForm.Handle, WM_TESTTHTOMAIN, 5, 2);
end
else
begin
SendMessage(MainForm.Handle, WM_TESTTHTOMAIN, 5, 3);
end;
Stream.Free;
end;
end;