Reputation: 1398
I wrote a function that gives me the length of a dynamic array by converting it to string and asking length(trim(string));
function arraylength(a: array of char): integer;
var i: integer;
s: string;
begin
for i:=0 to high(a) do
begin
s[i] := a[i-1];
Result := length(trim(s));
end;
end;
In my main program i read text into a string, convert it to array
procedure TForm1.Button2Click(Sender: TObject);
var i: integer;
begin
for i:=0 to length(sString) do
begin
cChar[i] := sString[i];
end;
end;
and do:
ShowMessage(IntToStr(arraylength(cChar)));
I get the error as stated in the title.
Upvotes: 0
Views: 2324
Reputation: 2950
When passing arrays to procedures and functions in delphi you should declare them as a separate type. Thus:
type
MyArray = array of char;
and then
function arraylength(a: MyArray ): integer;
BTW: why aren't you using built-in functions like Length() ? In Delphi2009 type string is unicode string, so Length returns Length in characters, not in bytes.
Upvotes: 4