Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between .Create and .Create() in Delphi?

I'm following along in Pawel Glowacki's Expert Delphi book. On page 98 he has the following onClick event handler:

procedure TFormFavJSON.btnReadDOMClick(Sender: TObject);
var
  favs: TFavorites; valRoot: TJSONValue;  objRoot: TJSONObject;
  valFavs: TJSONValue;  arrFavs: TJSONArray;
begin
  favs := TFavorites.Create;
  //
  // Several lines of code omitted
  //
  favs.Free;
end;

However when I type .Cre and use the code completion Ctrl + Space the IDE completes the code with a set of empty parenthesis.

favs := TFavorites.Create();

So which of the following is the most correct?

  favs := TFavorites.Create;
  favs := TFavorites.Create();
like image 281
Michael Riley - AKA Gunny Avatar asked Nov 29 '22 21:11

Michael Riley - AKA Gunny


1 Answers

They're both equally correct. Object Pascal allows you to omit the parentheses when the procedure or method requires no parameters, but also allows you to include them. It's up to you which you prefer.

like image 129
Ken White Avatar answered Dec 09 '22 15:12

Ken White