Can’t set Fire Monkey Form property

  

I am trying to initialize form properties in the program source file in a Fire Monkey application and it throws an exception. Here is the code:

uses
System.StartUpCopy,
FMX.Forms,
uMainForm in ‘Units\uMainForm.pas’ {MainForm},
UDataModule in ‘Units\UDataModule.pas’ {DataMod: TDataModule},
DataHelperClasses in ‘Units\DataHelperClasses.pas’,
EXDIntf in ‘Units\EXDIntf.pas’,
Exd in ‘Units\Exd.pas’;

{$R *.res}
var
ViewModel: TEXDViewModel;
begin
Application.Initialize;
Application.CreateForm(TDataMod, DataMod);
Application.CreateForm(TMainForm, MainForm);
ViewModel := TEXDViewModel.Create;
MainForm.Data := DataMod;
MainForm.ViewModel := ViewModel; //This throws an access violation exception
ViewModel.Data := DataMod;
Application.Run;
end.

I have no problem doing this in a VCL app. How do I fix it?

Comments are closed.