Главная страница
Top.Mail.Ru    Яндекс.Метрика
Текущий архив: 2003.10.23;
Скачать: CL | DM;

Вниз

Вызов процедуры потрисовки графика из другого потока   Найти похожие ветки 

 
Донской ©   (2003-10-10 14:53) [0]

Здравствуйте!!
У меня в отдельном потоке программа получает данные из порта.
А процедура, которая эти данные преобразовывает и рисует по ним график - в модуле главного окна (основного процесса).
Выглядит это в модуле потока так:

procedure ttmythread.execute;
begin
...
synchronize(StepCreateField);
...
synchronize(StepPaintGraf);
end;

procedure ttmythread.StepCreateField;// метод вызова процедуры
// создания компонента paintbox"a
begin
Form1.CreateMyPaintBox;
end;

procedure ttmythread.StepPaintGraf; // метод вызова процедуры
// прорисовки графика на созданном компоненте
begin
Form1.paintGarf;
end;


И при этом отрисовки не происходит.
Мало того, компонет вроде создается, потому что ругани от машины не слышно, но и компонента не видно. (а должно, потому что под ним создается tpanel, который уж точно должен быть заметен).

DEct дело только в потоке, потому что та же самая процедура работает при вызове ее из главного потока замечательно.

Что я в потоке сделал не так, подскажите, пожалуйста.


 
Семен Сорокин ©   (2003-10-10 14:59) [1]

на первый взгляд все нормально, приведи весь текст execute и как создаешь поток.


 
han_malign ©   (2003-10-10 15:04) [2]

MyPaintBox.Parent:=self???(Form1)


 
Донской ©   (2003-10-10 16:45) [3]

Естественно self, иниаче проверка раболты функций из основного окна не сработала бы.

Вот полный код потока, который создается просто - File/New/Tthread/
а потом вызывается главном потоке.


procedure TTestMaster.Execute;
var k,l,c:integer;
begin
{ Place thread code here }
Synchronize(stepSortCursors);
Synchronize(stepCalculateParameters);
Synchronize(stepWaightUser);
definedzero:=false;
MesureInProcess:=false;
NeedExit:=(terminated)or(errorcomcount>=Maxerrorcomcount);
while (not needexit)and(not DefinedZero) do
begin
if not mesureinprocess then
begin
synchronize(stepDefineZeroAndReturn_ShortTermAdjustment);
end;
sleep(2000);
NeedExit:=(terminated)or(errorcomcount>=Maxerrorcomcount);
end;
if NeedExit then
exit;
for c:=1 to IOcount do
begin
with form1 do with maindata do
begin
SaveTableAsNewIO:=true;
for k:=low(sortedcursors) to high(sortedcursors) do
begin
for l:=1 to WhatDoCount-1 do
begin
if sortedcursors[k]^.properties.WhatDo.Value=whatdoarray[l].Value then
begin
break;
end;
end;

case l of
0: // nothing
begin
end;
1,5: // StopWithoutMesure
begin
withmesure:=false;
definedStopinPoint:=false;
MesureInProcess:=false;
valueF:=sortedcursors[k]^.properties.confcursor^.properties.value;
ValueL:=sortedcursors[k]^.properties.value;
NeedExit:=(terminated)or(errorcomcount>=Maxerrorcomcount);
while (not needexit)and(not definedStopinPoint) do
begin
if not mesureinprocess then
begin
if k=low(sortedcursors) then
synchronize(stepStopinPoint_ShortTermAdjustment)
else
synchronize(stepStopInPoint_ExecuteControlOption);
end;
sleep(2000);
NeedExit:=(terminated)or(errorcomcount>=Maxerrorcomcount);
end;
if NeedExit then
exit;
end;
2,6: // StopWithMesure
begin
withmesure:=true;
definedStopinPoint:=false;
MesureInProcess:=false;
valueF:=sortedcursors[k]^.properties.confcursor^.properties.value;
ValueL:=sortedcursors[k]^.properties.value;
NeedExit:=(terminated)or(errorcomcount>=Maxerrorcomcount);
while (not needexit)and(not definedStopinPoint) do
begin
if not mesureinprocess then
begin
if k=low(sortedcursors) then
synchronize(stepStopinPoint_ShortTermAdjustment)
else
synchronize(stepStopInPoint_ExecuteControlOption);
end;
sleep(2000);
NeedExit:=(terminated)or(errorcomcount>=Maxerrorcomcount);
end;
if NeedExit then
exit;
if definedStopinPoint then
begin
DefinedFullFXTable:=false;
DefinedNextFXTable:=false;
NeedExit:=(terminated)or(errorcomcount>=Maxerrorcomcount);
while (not needexit)and(not definedFullFXtable) do
begin
if (not DefinedNextFXTable)and(not DefinedFullFXTable) then
begin
synchronize(stepFXTable);
end;
sleep(2000);
NeedExit:=(terminated)or(errorcomcount>=Maxerrorcomcount);
end;
if NeedExit then
exit;
if definedFullFXTable then
begin
AddIOToTestMainData;
SaveIOToDB(TestID,pointtoheadofsetof^.countOfIO,SaveTableAsNewIO);
FullingWindowFieldsFromBU(SaveTableAsNewIO);
end;
end;
end;


 
Донской ©   (2003-10-10 16:46) [4]

3,7: // ReversWithoutMesure
begin
withmesure:=false;
definedMesurewithreturn:=false;
MesureInProcess:=false;
valueF:=sortedcursors[k]^.properties.confcursor^.properties.value;
ValueL:=sortedcursors[k]^.properties.value;
NeedExit:=(terminated)or(errorcomcount>=Maxerrorcomcount);
while (not needexit)and(not definedMesurewithreturn) do
begin
if not mesureinprocess then
begin
if k=low(sortedcursors) then
synchronize(stepMesureWithReturn_ShortTermAdjustment)
else
synchronize(stepMesureWithReturn_ExecuteControlOption);
end;
sleep(2000);
NeedExit:=(terminated)or(errorcomcount>=Maxerrorcomcount);
end;
if NeedExit then
exit;
end;
4,8: // ReversWithMesure
begin
withmesure:=true;
definedMesurewithreturn:=false;
MesureInProcess:=false;
valueF:=sortedcursors[k]^.properties.confcursor^.properties.value;
ValueL:=sortedcursors[k]^.properties.value;
NeedExit:=(terminated)or(errorcomcount>=Maxerrorcomcount);
while (not needexit)and(not definedMesurewithreturn) do
begin
if not mesureinprocess then
begin
if k=low(sortedcursors) then
synchronize(stepMesureWithReturn_ShortTermAdjustment)
else
synchronize(stepMesureWithReturn_ExecuteControlOption);
end;
sleep(2000);
NeedExit:=(terminated)or(errorcomcount>=Maxerrorcomcount);
end;
if NeedExit then
exit;
if definedMesurewithreturn then
begin
DefinedFullFXTable:=false;
DefinedNextFXTable:=false;
NeedExit:=(terminated)or(errorcomcount>=Maxerrorcomcount);
while (not needexit)and(not definedFullFXtable) do
begin
if (not DefinedNextFXTable)and(not DefinedFullFXTable) then
begin
synchronize(stepFXTable);
end;
sleep(2000);
NeedExit:=(terminated)or(errorcomcount>=Maxerrorcomcount);
end;
if NeedExit then
exit;
if definedFullFXTable then
begin
{ВОТ ЗДЕСЬ ОНИ И ВЫЗЫВАЮТСЯ - МЕТОДЫ СОЗДАНИЯ И ПРОИСОВКИ !!!}
synchronize(stepAddIOTotestmaindata);
synchronize(stepSaveIOToDB);
synchronize(stepFullingWindowFieldsFromBU);
end;
end;
end;
else
end;
SaveTableAsNewIO:=false;
end;
end;
end;
end;

procedure ttestmaster.stepSortCursors;
begin
with form1 do
begin
fullingsortedcursors;
end;
end;

procedure ttestmaster.stepCalculateParameters;
begin
//


 
Донской ©   (2003-10-10 16:47) [5]


procedure ttestmaster.stepWaightUser;
label 10;
begin
//


 
Семен Сорокин ©   (2003-10-10 17:02) [6]

с with"ами не перемудрил? пробовал в отладке пройтись?


 
Донской ©   (2003-10-10 17:18) [7]

да, пробовал.
Я вот думаю.
Я в начале Execute использую With form1 do with maindata do/
так вот, там в теле этого метода дальше идет проверка значения переменных, орбъявленнях в разделе form1/public/

Это можно делать без вызова метода synchronize?
да и сама maindata - это переменная типа Record? объявленная там же.

Или стоит вообще исключить использование With form1 в теле метода Execute?


 
Семен Сорокин ©   (2003-10-10 17:24) [8]

Или стоит вообще исключить использование With form1 в теле метода Execute?
стоит попробовать обойтись без VCL


 
Донской ©   (2003-10-10 17:34) [9]

А какая разница между автоматически сгенерированном модуле TThread и написанном ручками?

ну создам я ручками Unit, перенесу туда весь код, и что?
Или я не понял?

Будет тот же самый класс...


 
Донской ©   (2003-10-10 17:35) [10]

а , в смысле рисовать не на потомке класса МСД а на своем собственном ?

Хм..


 
Донской ©   (2003-10-10 17:36) [11]

а , в смысле рисовать не на потомке класса VCL а на своем собственном ?

Хм..


 
Семен Сорокин ©   (2003-10-10 17:53) [12]

нет ты не понял, убери обращение к Form1 из Execute, наверное неправильно выразился


 
Семен Сорокин ©   (2003-10-10 17:54) [13]

обращайся только через synchronize


 
Донской ©   (2003-10-10 18:00) [14]

OK,
Спасибо, Семен Сорокин!!
Будем делать.



Страницы: 1 вся ветка

Текущий архив: 2003.10.23;
Скачать: CL | DM;

Наверх




Память: 0.51 MB
Время: 0.024 c
1-74229
Raptorus
2003-10-09 15:51
2003.10.23
Уважаемые, Мастера. Подскажите как из TList записать в TListBox


11-74102
Immortal_
2003-02-08 20:13
2003.10.23
String 2 File


9-73958
Juster~
2003-04-20 13:49
2003.10.23
Организация рендеринга


1-74283
KSergey
2003-10-10 18:10
2003.10.23
Default Button


14-74397
Lony
2003-10-06 11:55
2003.10.23
Пароль на вход в Windows2000