Главная страница
    Top.Mail.Ru    Яндекс.Метрика
Форум: "Основная";
Текущий архив: 2003.10.23;
Скачать: [xml.tar.bz2];

Вниз

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

 
Донской   (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;
Скачать: [xml.tar.bz2];

Наверх




Память: 0.49 MB
Время: 0.01 c
14-74469
cher_gvf
2003-10-03 12:41
2003.10.23
Запуск с помощью CreateProcess


1-74131
JibSkeart
2003-10-11 11:00
2003.10.23
TTreeView сохранение и загрузка дерева. как можно реализовать ?


3-74074
dgs
2003-10-01 17:54
2003.10.23
Использование в DLL соединения из вызывающего приложения


1-74151
ruslan_as
2003-10-10 17:35
2003.10.23
Как привязать программу к серверу?


1-74315
romeo
2003-10-12 02:36
2003.10.23
Как сразу выделить память для TComponent.Components?





Afrikaans Albanian Arabic Armenian Azerbaijani Basque Belarusian Bulgarian Catalan Chinese (Simplified) Chinese (Traditional) Croatian Czech Danish Dutch English Estonian Filipino Finnish French
Galician Georgian German Greek Haitian Creole Hebrew Hindi Hungarian Icelandic Indonesian Irish Italian Japanese Korean Latvian Lithuanian Macedonian Malay Maltese Norwegian
Persian Polish Portuguese Romanian Russian Serbian Slovak Slovenian Spanish Swahili Swedish Thai Turkish Ukrainian Urdu Vietnamese Welsh Yiddish Bengali Bosnian
Cebuano Esperanto Gujarati Hausa Hmong Igbo Javanese Kannada Khmer Lao Latin Maori Marathi Mongolian Nepali Punjabi Somali Tamil Telugu Yoruba
Zulu
Английский Французский Немецкий Итальянский Португальский Русский Испанский