Hello.
Maybe I have a misconception with the language (freepascal), but I saw something I think is strange.
Have this example class:
TMyObject = class
private
fstr: String;
public
constructor Create(param: String);
function getStr: String;
end;
constructor TMyObject.Create(param: String);
begin
fstr := param;
end;
function TMyObject.getStr: String;
begin
Result := fstr;
end;
And this code
procedure TfrmMain.Button1Click(Sender: TObject);
var
obj: TMyObject;
begin
ShowMessage(obj.getStr);
end;
I expect to have some problems on the ShowMessage line, runtime error or alike. But no, it works, showing weird characters in the screen.
Shouldn't I instantiate obj first, with method TMyObject.Create(String), before calling its methods?
Also, if I check obj agains nil, it fails (says it's not nil), unless I initialize the variable, like this:
procedure TfrmMain.Button1Click(Sender: TObject);
var
obj: TMyObject;
begin
if obj = nil then ShowMessage('obj is nil'); //Nothing shows
end;
procedure TfrmMain.Button1Click(Sender: TObject);
var
obj: TMyObject = nil;
begin
if obj = nil then ShowMessage('obj is nil'); //now I get the message
end;
It looks like obj is created automatically, but I don't know why.
Any help or explanations?
Thanks!