[fpc-pascal] Using "array of xxx" in function call, Delphi compatibility

Juha Manninen juha.manninen62 at gmail.com
Sat Aug 13 12:28:06 CEST 2011


Hi

While reading a bug report I made the following experiment with Delphi 2009
and then with Lazarus + FPC 2.4.4.

TMainMenu.Items is of type TMenuItem. TMenuItem has only one version of
"Add" method and it takes another TMenuItem as parameter (checked from VCL
source).
Still, to my surprise, the code works in Delphi.

FPC says: Error: Incompatible type for arg no. 1: Got "Dynamic Array Of
TMenuItem", expected "TMenuItem"
which is what I expected also from Delphi.

---
procedure TForm1.FormCreate(Sender: TObject);
var
  ma: array of TMenuItem;
  mi: TMenuItem;
begin
  SetLength(ma, 2);

  mi := TMenuItem.Create(MainMenu1);
  mi.Caption := 'File';
  ma[0] := mi;

  mi := TMenuItem.Create(MainMenu1);
  mi.Caption := 'Help';
  ma[1] := mi;

  MainMenu1.Items.add(ma); // Works in Delphi
end;
---

Is this a known issue?

Regards
Juha
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20110813/6308b5cb/attachment.html>


More information about the fpc-pascal mailing list