Masterguba
Programmer
What I'm trying to do is to create dynamically a component class that will contain other components.
It seems that I cannot or I do not do the creation of subcomponents correctly.
The project compiles fine, but when it runs it rises Access Violation Error.
This is the code.
What I'm doing wrong ?
unit Unit1;
interface
uses
System.SysUtils, System.Types, System.UITypes,
System.Classes, System.Variants,
FMX.Types, FMX.Graphics, FMX.Controls, FMX.Forms,
FMX.Dialogs, FMX.StdCtrls, FMX.Objects, FMX.Layouts;
type
TMyIconLabel = class(TLabel)
public
Constructor Create(AOwner : TComponent);
end;
TMyIconRectangle = class(TRectangle)
public
Constructor Create(AOwner : TComponent);
end;
TMyIconObject = class(TLayout)
IconLabel : TMyIconLabel;
IconRectangle : TMyIconRectangle;
private
{ Private declarations }
public
{ Public declarations }
end;
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
MyIcons : Array[1..10] of TMyIconObject;
implementation
{$R *.fmx}
Constructor TMyIconLabel.Create(AOwner : TComponent);
Begin
inherited;
End;
Constructor TMyIconRectangle.Create(AOwner : TComponent);
Begin
inherited;
End;
procedure TForm1.FormCreate(Sender: TObject);
Var i : Integer;
begin
for i := 1 to 10 do
Begin
MyIcons := TMyIconObject.Create(Form1);
MyIcons.Width := 50;
MyIcons.Height := 50;
MyIcons.Position.X := 50 + (75 * i);
MyIcons.Position.Y := 100;
MyIcons.IconRectangle.Align := TAlignLayout.Client;
MyIcons.IconRectangle.Fill.Color := $FFFFFFFF;
MyIcons.IconLabel.Align := TAlignLayout.Client;
MyIcons.IconLabel.Text := 'Icon #' + IntToStr(i);
End;
end;
end.
It seems that I cannot or I do not do the creation of subcomponents correctly.
The project compiles fine, but when it runs it rises Access Violation Error.
This is the code.
What I'm doing wrong ?
unit Unit1;
interface
uses
System.SysUtils, System.Types, System.UITypes,
System.Classes, System.Variants,
FMX.Types, FMX.Graphics, FMX.Controls, FMX.Forms,
FMX.Dialogs, FMX.StdCtrls, FMX.Objects, FMX.Layouts;
type
TMyIconLabel = class(TLabel)
public
Constructor Create(AOwner : TComponent);
end;
TMyIconRectangle = class(TRectangle)
public
Constructor Create(AOwner : TComponent);
end;
TMyIconObject = class(TLayout)
IconLabel : TMyIconLabel;
IconRectangle : TMyIconRectangle;
private
{ Private declarations }
public
{ Public declarations }
end;
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
MyIcons : Array[1..10] of TMyIconObject;
implementation
{$R *.fmx}
Constructor TMyIconLabel.Create(AOwner : TComponent);
Begin
inherited;
End;
Constructor TMyIconRectangle.Create(AOwner : TComponent);
Begin
inherited;
End;
procedure TForm1.FormCreate(Sender: TObject);
Var i : Integer;
begin
for i := 1 to 10 do
Begin
MyIcons := TMyIconObject.Create(Form1);
MyIcons.Width := 50;
MyIcons.Height := 50;
MyIcons.Position.X := 50 + (75 * i);
MyIcons.Position.Y := 100;
MyIcons.IconRectangle.Align := TAlignLayout.Client;
MyIcons.IconRectangle.Fill.Color := $FFFFFFFF;
MyIcons.IconLabel.Align := TAlignLayout.Client;
MyIcons.IconLabel.Text := 'Icon #' + IntToStr(i);
End;
end;
end.