Answer the question
In order to leave comments, you need to log in
Answer the question
In order to leave comments, you need to log in
If you create windows of one class, then all functions belonging to this class will be implemented in all copies. Example:
type
TNotepad = class(TForm) //Предок всех классов для записи блокнота
public
class var OnAfterCreate: TNotifyEvent; //событие, для реакции после создания
constructor Create(AOwner: TComponent); override; //второй возможный
//вариатнвариант
end;
TMainForm = class(TForm)
procedure FormCreate(Sender: TObject);
public
procedure DoAfterCreate1(Sender:TObject); //вариант 1
procedure DoAfterCreate2(Sender:TObject); //вариант 2
end;
constructor TNotepad.Create(AOwner: TComponent);
begin
inherited;
//варант 1
if Assigned(OnAfterCreate) then
OnAfterCreate(Self);
//*1
//вариант 2
if Assigned(Screen.MainForm ) then
if Screen.MainForm is TMainForm then
TMainForm(Screen.MainForm).DoAfterCreate2(Self);
//*2
end;
procedute TMainForm.FormCreate(Sender:TObject);
begin
TNotepad.OnAfterCreate := Self.DoAfterCreate1; //вариант 1
end;
The component event is set to a certain type, so you need to look first of all at what type the event has. Under it, a procedure or object function is created. For example, the implementation for the button and for the form for one single procedure, if it is known that it exists:
procedure TForm1.OnCklickFrom2(Sender: TObject);
begin
Caption := TComponent(Sender).Name;
end;
procedure TForm1.FormCreate(Sender: TObject);
var
Frm2 : TForm2;
begin
Frm2 := TForm2.Crete(Application);
Frm2.OnClick := Self.OnCklickFrom2;
Frm2.Button1.OnClick := Self.OnCklickFrom2;
end;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question