As it pertains to Delphi...
When a variable is declare of a certain type, is it initialized to an OBJECT of that type? Or must the variable be assigned an expression which returns an object of that type?
I'm coming from a strong Java background. What I mean to ask is this... In Java, say you declare an instance variable of a user defined type named Orange. Which would look like this:
private Orange _fruit;
The variable _fruit still holds a reference to null until actually assigned an instance of the Orange class, like this:
_fruit = new Orange();
In Delphi if I declare a variable of type TForm, like this:
var
Form : TForm;
Is Form initlized to a TForm object? Or is it still nil?
I'm asking because I'm getting an error when trying to compile a small bit of code which is showen below:
Here is the Main unit:
unit Main;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils,
System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Second;
type
TForm1 = class(TForm)
ShowForm2: TButton;
procedure ShowForm2Click(Sender: TObject);
end;
var
Form1: TForm1;
SecondForm : TSecondForm;
implementation
{$R *.dfm}
procedure TForm1.ShowForm2Click(Sender: TObject);
begin
SecondForm.ShowModal;
end;
end.
and here is the Second unit:
unit Second;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs,
Vcl.StdCtrls;
type
TSecondForm = class(TForm)
Label1: TLabel;
end;
var
SecondForm: TSecondForm;
implementation
{$R *.dfm}
end.
The error I'm getting when I try to compile is exactly: "Access violation at address 005B17F9 in module 'Multiple.exe'. Read of address 00000000." I was thinking that it's because I don't somehow initialize the variable SecondForm in unit Main? However, I tried to place 'SecondForm.Create' in the ShowForm2Click procedure and I get the same error. Am I get this error because SecondForm is unassigned? Does it need to be initialized? Or is it?
Note: I'm three days new to Delphi. Please be considerate of that.