1
votes

I am porting over a VCL component to FMX. 99% of of the code is pure object pascal, so that works just fine - but i have a method which creates a form, poulates it with buttons and a text-box, and this quite simply doesnt work under FMX.

The whole point to creating the form manually and then populating it from code was to make sure it compiled under both VCL, LCL and FMX; and that it also displays just fine under iOS, Android and whatever platform is used.

But i keep getting "Resource /classname/ not found", where /classname/ is whatever classname i give my temporary form class.

Something as simple as this produces the error:

type
TMyDialogForm = Class(TForm);

procedure TForm1.Button1Click(Sender: TObject);
var
  LDialog:  TMyDialogForm;
begin
  LDialog := TMyDialogForm.Create(application.MainForm);
  try
    LDialog.Caption := 'Yahoo!';
  finally
    LDialog.Free;
  end;
end;

Since the error involves resource, I suspect that it is looking for some type of layout data. I have just started playing around with FMX, and i did notice that different platforms allow for different layouts. But I must admit I expected it to fall-back to the default theme, no matter what platform you target.

So -- how exactly do i create a form by code, populate it and display ut using Firemonkey without running into this kind of bug? It works perfectly fine under VCL and LCL, but FMX keeps going on about resources.

Please dont tell me all forms MUST be designed?

1

1 Answers

5
votes

As @RemyLebeau answered a similar question in the delphi forum (How to create a TForm at runtime?):

You are calling the TForm constructor that invokes DFM streaming. The reason it does not fail in non-FMX apps is because TCustomForm.Create() filters out TForm specifically so it won't try to stream. In FMX, TCommonCustomForm.Create() filters out TCommonCustomForm instead of TForm, which is why your TForm in FMX is trying to stream itself.

Since you know that there is no DFM, you should be using the non-DFM constructor instead, in both VCL and FMX:

FRM := TForm.CreateNew(Application);