type
TByteDynArray = array of Byte; // <--This is in Delphi 7
types.pas
PByteDynArray = ^TByteDynArray;
function DoStuff(I: PByteDynArray): Byte;
begin
Result := I[0];
end;
Delphi 7 gives me the error: Array type required
Now why can't Delphi figure out the array type?
If you haven't figured it out already:
Maybe because I is a pointer type?
Why don't you use I^[0] instead of I[0]?
Regards, JohnH
> Consider the following:
>
> type
> TByteDynArray = array of Byte; // <--This is in Delphi 7
> types.pas
> PByteDynArray = ^TByteDynArray;
>
> function DoStuff(I: PByteDynArray): Byte;
> begin
> Result := I[0];
> end;
>
> Delphi 7 gives me the error: Array type required
You give it a pointer to an array type, not an array type. Compilers
only do what you tell them, not what you want to tell them. So you must
pass @MyArray, and do:
So do:
if (I <> nil) and (Length(I^) > 0) then
Result := I^[0];
But why don't you simply pass a TByteDynArray instead?
function DoStuff(I: TByteDynArray): Byte;
begin
if Length(I) > 0 then
Result := I[0];
end;
Now you can simply pass the array.
--
Rudy Velthuis (TeamB)
"We should leave our minds open, but not so open that our brains
fall out." - Alan Ross Anderson
> But why don't you simply pass a TByteDynArray instead?
Yeah, i figured this out later. A lot of careful reading about untyped
constant parameters, open array parameters, dynamic array parameters,
reference counting, etc.
Thanks for the reply.
"Rudy Velthuis (TeamB)" <rvel...@gmx.de> wrote in message
news:3de37358$1...@newsgroups.borland.com...