Search code examples
delphicode-completion

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();

Solution

  • Makes no difference. Pascal allows either syntax. I prefer without parentheses when there is no need.