Пост MrAnderson - сообщение в Вопрос "События OnClick в MyClass" был отмечен как ответ
Не знаю почему но вот так заработало.
Может кто нибудь прояснить почему.
unit Unit2;
interface
uses
System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.Objects, FMX.Controls.Presentation, FMX.StdCtrls,
FMX.Layouts;
type
TNotifyEvent = procedure (Sender: TObject) of object;
TTapEvent = procedure(Sender: TObject; const Point: TPointF) of object;
MyType = class //class(TObject)
MyButt:TButton;
private
fNGP: string;
function GetOnClick: TNotifyEvent;
procedure SetOnClick(const Value: TNotifyEvent);
function GetTapClick: TTapEvent;
procedure SetTapClick(const Value: TTapEvent);
public
Property NGP:string read fNGP;
procedure ButtonClick(Sender: TObject);
procedure TapClick(Sender: TObject; const Point: TPointF);
property OnButtonClick : TNotifyEvent Read GetOnClick Write SetOnClick;
property OnTapClick : TTapEvent Read GetTapClick Write SetTapClick;
constructor Create(NewId:integer;NewNGP:string);
end;
type
TForm2 = class(TForm)
Button1: TButton;
VertScrollBox1: TVertScrollBox;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form2: TForm2;
myitem:array of MyType;
implementation
{$R *.fmx}
{ MyType }
procedure MyType.ButtonClick(Sender: TObject);
begin
ShowMessage((Sender as TButton).Name +' NGP ['+self.fNGP+']');
end;
constructor MyType.Create(NewId:integer;NewNGP:string);
Var RectForButt:TRectangle;
begin
fNGP:=NewNGP;
RectForButt:= TRectangle.Create(nil);
RectForButt.Parent := Form2.VertScrollBox1;
RectForButt.Align := TAlignLayout.Top;
RectForButt.Margins.Top:=2;
RectForButt.Margins.Bottom:=0;
RectForButt.Margins.Left:=0;
RectForButt.Margins.Right:=0;
RectForButt.Stroke.Kind:=TBrushKind.None;
RectForButt.Fill.Kind:=TBrushKind.None;
RectForButt.Height:=150;
RectForButt.HitTest:=false;
MyButt:=TButton.Create(Form2);
MyButt.Width:=100;
MyButt.Parent:=RectForButt;
MyButt.HitTest:=true;
MyButt.Align := TAlignLayout.Center;
MyButt.Text:='Моя кнопка'+IntToSTr(NewId);
MyButt.Name:='MyButton'+IntTOSTr(NewId);
MyButt.TextSettings.Font.Size:=12;
MyButt.OnClick:=self.OnButtonClick;
// MyButt.OnTap:=self.OnTapClick;
end;
function MyType.GetOnClick: TNotifyEvent;
begin
Result:=self.ButtonClick;
end;
function MyType.GetTapClick: TTapEvent;
begin
Result:=self.TapClick;
end;
procedure MyType.SetOnClick(const Value: TNotifyEvent);
begin
MyButt.OnClick:=value;
end;
procedure MyType.SetTapClick(const Value: TTapEvent);
begin
MyButt.OnTap:=Value;
end;
procedure MyType.TapClick(Sender: TObject; const Point: TPointF);
begin
ShowMessage((Sender as TButton).Name +' NGP ['+NGP+']');
end;
procedure TForm2.Button1Click(Sender: TObject);
begin
SetLength(myitem,Length(myitem)+1);
myitem[Length(myitem)-1]:=MyType.Create(Random(1000),'ПРОСТОЕ '+IntToStr(Random(100)));
end;
end.