1
Hello! To use in game production, I would like to understand how to keep an image in a form through Firemonkey. The code I have so far is as follows::
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 section makes no exception and according to the Debugger, all the code is running. However the image is not shown.
Am I forgetting something? Do I need any other settings I’m not aware of? Am I doing everything wrong? Any suggestions?
Have you tried drawing without bitmap? Why are you using a thread in this example?
– EMBarbosa
Otherwise I’d need one
TTimer, but as I will need other processing I preferred a thread. However I have already discovered the problem. I am using theSetSizeright after the creation ofTBitmapand image loading. And this apparently erases the current content ofTBitmap. Without theSetSizethe code above works.– Guill
in this case, you should answer that question yourself.
– EMBarbosa
@Guill, you would have to change your code and add as a response? :)
– David