Why this command is working like "Self.Close" or like that?
First, I think that was like this:
MyHelloVar. {spaces...} Close;
or be:
Command 1: MyHelloVar. // but this wont compile it, or yes?
Command 2: {Self.} Close;
The "MyHelloVar" itself is behaving as if she were my variable (instance) of the main form.
Is it true what I'm understanding here?
unit Unit1;
interface
uses
Winapi.Windows,
Winapi.Messages,
System.SysUtils,
System.Variants,
System.Classes,
Vcl.Graphics,
Vcl.Controls,
Vcl.Forms,
Vcl.Dialogs,
Vcl.StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
(* Summary:
- RAD Studio 11.1 Alexandria
- VCL Project 32bits (common case)
- 1 form = my main form created automatically by IDE
- 1 form = my second form not created automatically
- 1 button to test!
*)
procedure TForm1.Button1Click(Sender: TObject);
var
MyHelloVar: TForm;
begin
// That's crazy behaviour!
//
MyHelloVar.Close; // this is close my "App" like "Self.Close" do it!
//
end;
end.
TForm
) are uninitialized, so you are callingTForm.Close
on a random pointer (whatever happens to be in your computer's RAM at that place). Then anything can happen. Different things can happen every time you run the code. This is a bug.