Hello! To use in game production, I'd like to understand how to keep an image in a form through Firemonkey. The code I have so far is this:
program TestCase;
uses
UITypes, Classes, Types,
FMX.Forms, FMX.Graphics, FMX.Objects;
type
TMainForm = class(TForm)
constructor CreateNew(AOwner: TComponent; Dummy: NativeInt = 0); Override;
procedure AppEnd(Sender : TObject; var Action : TCloseAction);
procedure PaintStuff(Sender : TObject; Canvas : TCanvas);
end;
var
T : TThread;
B : TBitmap;
F : TMainForm;
{ TMainForm }
procedure TMainForm.AppEnd(Sender: TObject; var Action: TCloseAction);
begin
T.Terminate;
Action := TCloseAction.caFree;
Application.Terminate;
end;
constructor TMainForm.CreateNew(AOwner: TComponent; Dummy: NativeInt = 0);
begin
inherited CreateNew(nil);
with TPaintBox.Create(Self) do
begin
Width := ClientWidth;
Height := ClientHeight;
Parent := Self;
OnPaint := PaintStuff;
end;
OnClose := AppEnd;
end;
procedure TMainForm.PaintStuff(Sender: TObject; Canvas: TCanvas);
begin
Canvas.BeginScene();
Canvas.DrawBitmap(B, ClientRect, ClientRect, 100);
Canvas.EndScene;
end;
begin
Application.Initialize;
B := TBitmap.CreateFromFile('test.png');
B.SetSize(90, 100);
F := TMainForm.CreateNew(nil);
F.Show;
T := TThread.CreateAnonymousThread(procedure() begin
F.Invalidate;
TThread.Sleep(10);
end);
T.Start;
Application.Run;
end.
The above excerpt throws no exception, and according to the debugger , all code is running. However, the image is not displayed.
Am I forgetting something? Do I need any more configuration I'm not aware of? Am I doing everything wrong? Any suggestions?