Коллеги, здравствуйте. Помогите пожалуйста с работой потоков. При запуске потока, появляется индикатор и исправно крутится. В какой то момент он залипает и перестает крутиться и так до конца работы потока. Понимаю, что в потоке идет работа с визуальными компонентами, по этому скорее всего и залипает индикатор. Как исправить/оптимизировать код? Спасибо.
DelOff = class (TThread)
protected
FOnTaskStarted: TThreadMethod;
FOnTaskFinished: TThreadMethod;
procedure DoStarted;
procedure DoFinished;
procedure load;
procedure Execute; override;
public
property OnTaskStarted: TThreadMethod read FOnTaskStarted write FOnTaskStarted;
property OnTaskFinished: TThreadMethod read FOnTaskFinished write FOnTaskFinished;
end;
procedure DelOff.DoFinished;
begin
Add.Layout1.Visible:=false;
if Assigned (Add.FindComponent('Null') as TLayout)
then
(Add.FindComponent('Null') as TLayout).Free;
end;
procedure DelOff.DoStarted;
begin
Add.Layout1.Visible:=true;
end;
procedure DelOff.load;
begin
try
ReOpen;
ClientModule2.ServerMethods1Client.Number13(a,b,g,h);
a:='1';
ReOpen;
offerlist1.Lines.Text:=ClientModule2.ServerMethods1Client.Number12(a,b,g,h);
a:='2';
ReOpen;
sumofferlist1.Lines.Text:=ClientModule2.ServerMethods1Client.Number12(a,b,g,h);
a:='3';
ReOpen;
keyofferlist1.Lines.Text:=ClientModule2.ServerMethods1Client.Number12(a,b,g,h);
ReOpen;
offercount:=ClientModule2.ServerMethods1Client.Number11(a,b,g,h);
except
ANM.Show;
Add.Visible:=false;
ShowmessageToast('Ошибка загрузки',TJToast.JavaClass.LENGTH_LONG);
Value := Trim('10,500');
if Add.CheckPermission then
if Value.Contains(',') then
TVibratorHelper.vibrate(Value.Split([',']), -1)
else
TVibratorHelper.vibrate(Value.ToInt64);
end;
end;
procedure DelOff.Execute;
begin
inherited;
//Удаление из БД продукта
try
try
Synchronize(DoStarted);
updatecount:=StringReplace((Add.FindComponent('LabelIntro') as TLabel).Hint, 'Rec', '', [rfReplaceAll]);
a:=(Add.FindComponent('NameProduct'+updatecount) as TLabel).Hint;
di:= TZDeviceInfo.Create;
b:=StringReplace(di.DeviceID, '=', '', [rfReplaceAll]);
if(internet='true') and (server='true')
then
begin
EditCase:='false';
Add.PSB.AutoCalculateContentSize:=false;
Add.PSB.EnabledScroll:=true;
Add.PSB.AutoCalculateContentSize:=true;
synchronize(load);
if Assigned (Add.FindComponent((Add.FindComponent('LabelDel') as TLabel).Hint))
then
begin
(Add.FindComponent((Add.FindComponent('LabelDel') as TLabel).Hint) as TRectangle).Free;
(Add.FindComponent('RecEdit') as TRectangle).Free;
end;
Add.PSB.ScrollTo(0,0,true);
for countload:=0 to StrToInt(offercount)-1 do
begin
(Add.FindComponent('XRun'+IntToStr(countload)) as TFloatAnimation).Enabled:=false;
(Add.FindComponent('x'+IntToStr(countload)) as TImage).Opacity:=0;
(Add.FindComponent('VRun'+IntToStr(countload)) as TFloatAnimation).Enabled:=false;
(Add.FindComponent('v'+IntToStr(countload)) as TImage).Opacity:=0;
end;
end
else
begin
ShowmessageToast('Нет интернета',TJToast.JavaClass.LENGTH_LONG);
Value := Trim('10,500');
if Add.CheckPermission then
if Value.Contains(',') then
TVibratorHelper.vibrate(Value.Split([',']), -1)
else
TVibratorHelper.vibrate(Value.ToInt64);
end;
finally
Synchronize(DoFinished);
end;
except
ANM.Show;
Add.Visible:=false;
ShowmessageToast('Ошибка загрузки',TJToast.JavaClass.LENGTH_LONG);
Value := Trim('10,500');
if Add.CheckPermission then
if Value.Contains(',') then
TVibratorHelper.vibrate(Value.Split([',']), -1)
else
TVibratorHelper.vibrate(Value.ToInt64);
end;
end;