A
A
Andrey2017-05-17 12:03:42
Delphi
Andrey, 2017-05-17 12:03:42

How to create form close event from another Unit?

The bottom line is this: in Delphi (and don't ask why in Delphi) you need to create a form from another in one unit. This is done by connecting the appropriate Unit.

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls, LView;
...
procedure TForm2.ButtonForwardClick(Sender: TObject);
begin
  LView.name := 'l'+Form2.RadioGroup1.ItemIndex+'.rtf'; // LView - 3-й юнит
  Form3.Create(self);
  Form2.Enabled := false;
end;

After form 3 is created, the second one is disabled. However, it cannot be included from the 3rd unit, because the compiler starts to swear at the cyclicity of unit calls.
The question is this: is it possible to register an event for closing form 3 in unit 2?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Mercury13, 2017-05-17
@worldand

1. Move the " usesappropriate form" from interface to implementation. Such cyclic calls are allowed.
A good rule of thumb: anything - uses, const, var - is desirable to keep in the implementation, unless they are needed by the interface.
However, such a cyclic "lump of dirt" suggests that the architecture of the program is poorly thought out, and this is undesirable for large programs.
2. Explicitly incorrect code Form3.Create(self);
If you create a form, then it is correct Form3 := TForm3.Create(self);
. If someone created it, and you called the constructor again, why is this?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question