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();
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With