Autor Beitrag
Jerk
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 251

Vista Ultimate, Ubuntu
Turbo Delphi 2006
BeitragVerfasst: Fr 08.08.08 21:48 
Ich habe eine Prozedur geschrieben um ein Feld in einem Dyn Array zu löschen und die anderen aufrücken zu lassen.

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
Procedure TToolSet.DeleteField(var DynArray: array of string; Index: Integer);
var
 i : Integer;
begin
 if (Index > -1and (Index < Length(DynArray)) then   // Index muss größer als -1 und max. genauso groß wie das letzte Feld im Array sein.
 begin
  if Index<Length(DynArray)-1 then                     // Wenn Index kleiner als Letztes Feld im Array
   for i := Index to Length(DynArray)-2 do
    DynArray[i] := DynArray[i+1];
  setLength(DynArray,Length(DynArray)-1);             // <- Fehler
 end;
end;


Beim setLength bekomme ich allerdings einen Fehler:
E2008 Inkompatible Typen

Ich habe schon @DynArray probiert, da kommt das gleiche und bei ^DynArray kommt E2035 Nicht genügend wirkliche Parameter.
Luckie
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Fr 08.08.08 23:22 
Wie hast du denn das dynamische Array deklariert? Normaler weise sollte es so funktionieren.
Jerk Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 251

Vista Ultimate, Ubuntu
Turbo Delphi 2006
BeitragVerfasst: Fr 08.08.08 23:23 
Der Fehler kommt beim Compilen, d.h. die Procedure wird garnicht aufgerufen.
Christian S.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 20451
Erhaltene Danke: 2264

Win 10
C# (VS 2019)
BeitragVerfasst: Fr 08.08.08 23:24 
Versuch mal:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
type
  TStringArray = Array of String;

(* ... *)

Procedure TToolSet.DeleteField(var DynArray: TStringArray; Index: Integer);

_________________
Zwei Worte werden Dir im Leben viele Türen öffnen - "ziehen" und "drücken".
Jerk Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 251

Vista Ultimate, Ubuntu
Turbo Delphi 2006
BeitragVerfasst: Fr 08.08.08 23:27 
user profile iconChristian S. hat folgendes geschrieben:
Versuch mal:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
type
  TStringArray = Array of String;

(* ... *)

Procedure TToolSet.DeleteField(var DynArray: TStringArray; Index: Integer);


Nach wie vor, Inkompatible Typen.

Wie gesagt ich rufe die Procedure nichtmal auf, der Compiler meckert bereits.


Kann jemand die Procedure mal bei sich Compilen, evtl liegt es ja an Delphi 2006 ?
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19341
Erhaltene Danke: 1752

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Sa 09.08.08 01:56 
Also mit Christians Tipp lässt es sich bei mir unter D 2006 aber (wie ich nicht anders erwartet hatte) kompilieren... :nixweiss: :gruebel:
Jerk Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 251

Vista Ultimate, Ubuntu
Turbo Delphi 2006
BeitragVerfasst: Sa 09.08.08 11:59 
Habe es heute nochmal ausprobiert, jetzt funktionierts. Bei der Umsetzung von Christain S. Vorschlag hab ich gestern wohl irgendwas falsch gemacht.

Vielen Dank aufjedenfall jetzt funktioniert es!