V
V
Vol4_OK2014-01-31 20:28:14
Delphi
Vol4_OK, 2014-01-31 20:28:14

How to write procedures for dynamic objects in Delphi?

How to make events for dynamic forms? And write code for them.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
svd71, 2014-01-31
@Vol4_OK

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;

S
svd71, 2014-01-31
@svd71

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;

V
Vol4_OK, 2014-01-31
@Vol4_OK

I'm creating a notepad, and I'm developing the ability to use. many windows. How can I create a window many times, and so that there are all functions that are in the example window?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question