threads and ttask delphi fmx?

  

i am trying to do some processing on second thread and for that i am currently using TTask and currently coded this thing with the knowledge i gained from previous explained questions here and in other tutorials :

procedure Process;
var
Task: ITask;
sMS, pMS, pMS2: TMemoryStream;
Bitmap1, Bitmap2, Bitmap3: TBitmap;
sRect: TRect;
begin
Form2.AniIndicator1.Visible := true;
Task := TTask.Create(
procedure
begin
sPdf := TDebenuPDFLibrary1613.Create;
sPdf.UnlockKey(‘stackoverflow@1234’);
if sPdf.LoadFromFile(FileName, ‘RAMBO@45454593’) = 1 then
begin
sPdf.SetOrigin(1);
sPdf.SelectRenderer(4);
sPdf.SetPDFiumFileName(‘eLibUM32.dll’);
pMS := TMemoryStream.Create;
pMS2 := TMemoryStream.Create;
try
sPdf.SetPageBox(2, 37, 659, 243, 152);
sPdf.RenderPageToStream(300, 0, 5, pMS);
Bitmap1 := TBitmap.CreateFromStream(pMS);
sPdf.SetPageBox(2, 314, 659, 243, 152);
sPdf.RenderPageToStream(300, 0, 5, pMS2);
Bitmap2 := TBitmap.CreateFromStream(pMS2);
with sRect do
begin
Top := 0;
Left := 0;
Width := Bitmap1.Width;
Height := Bitmap1.Height;
end;
Bitmap3:= TBitmap.Create;
with Bitmap3 do
begin
Height := Bitmap1.Height;
Width := Bitmap1.Width * 2 + 5;
Clear(TAlphaColors.White);
CopyFromBitmap(Bitmap1, sRect, 0, 0);
CopyFromBitmap(Bitmap2, sRect, sRect.Width + 5, 0);
end;
TThread.Queue(TTHread.CurrentThread, procedure
begin
Form2.AniIndicator1.Visible := False;
Form2.Image1.Bitmap.Assign(Bitmap3);
end);
finally
pMS.Free;
pMS2.Free;
end;
end else
TThread.Queue(TThread.CurrentThread,
procedure
begin
ShowMessage(‘Password Error !’);
end);
sPdf.Free;
end);
Task.Start;
end;

but sometimes it does not loads the bitmap into image1 of form2.
am i doing any mistakes in task or in que of thread ?

Comments are closed.