Wie übergebe ich ein Array als Referenz-Parameter an eine Prozedur? Wenn ich schreibe <p>
procedure TForm1.Callother(var MyAr:array [1..5] of Char);
dann streikt der Compiler.
(*Er streikt auch bei:
procedure TForm1.Callother(MyAr:array[1..5] of Char);*)
Wenn ich schreibe <p>
procedure TForm1.Callother(var MyAr:array of Char);<p>
dann läßt der Compiler das durchgehen, schickt mir aber zur Laufzeit eine Zugriffsverletzung, nachdem ich die Einzelwerte geändert habe. Beispiel:<pre>
procedure TForm1.Button1Click(Sender: TObject);
var MyAr: array[1..5] of Char;
begin
MyAr[1]:='H';
MyAr[2]:='a';
MyAr[3]:='n';
MyAr[4]:='s';
MyAr[5]:='i';
Label1.Caption:=MyAr;
Callother(MyAr);
end;
procedure TForm1.Callother(var aText:array of Char);
var i:integer;
begin
aText[1]:='M';
aText[2]:='a';
aText[3]:='u';
aText[4]:='s';
aText[5]:='i';
end;</pre>
procedure TForm1.Callother(var MyAr:array [1..5] of Char);
dann streikt der Compiler.
(*Er streikt auch bei:
procedure TForm1.Callother(MyAr:array[1..5] of Char);*)
Wenn ich schreibe <p>
procedure TForm1.Callother(var MyAr:array of Char);<p>
dann läßt der Compiler das durchgehen, schickt mir aber zur Laufzeit eine Zugriffsverletzung, nachdem ich die Einzelwerte geändert habe. Beispiel:<pre>
procedure TForm1.Button1Click(Sender: TObject);
var MyAr: array[1..5] of Char;
begin
MyAr[1]:='H';
MyAr[2]:='a';
MyAr[3]:='n';
MyAr[4]:='s';
MyAr[5]:='i';
Label1.Caption:=MyAr;
Callother(MyAr);
end;
procedure TForm1.Callother(var aText:array of Char);
var i:integer;
begin
aText[1]:='M';
aText[2]:='a';
aText[3]:='u';
aText[4]:='s';
aText[5]:='i';
end;</pre>
Comment