Autor Beitrag
daggit
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 56



BeitragVerfasst: Sa 14.10.06 14:24 
Hi,

habe gerade folgendes Problem.
Meine Anwendung enthält ein globales Array, welches je Schublade einen Record enthält.
Nun möchte ich einen bestimmten Index aus dem Array entfernen. Dazu erstelle ich mir ein Hilfsarray, in das per schleife alle Inhalte von Array 1 kopiert werden (mit ausnahme des zu löschenden indexes). Soweit so gut :).
Nun soll aber das eigentliche Array die Inhalte meines Hilfsarrys erhalten. Und genau hier bekomme ich immer folgende Fehlermeldung :"Inkompatible Typen".
Beide Arrays wurden aber gleich deklariert.

Meine zuweisung, welche den Fehler erzeugt lautet wie folgt:
ausblenden Delphi-Quelltext
1:
A_MyData :=  copy(A_MyData_HilsArray, 0 , length(A_MyData_HilsArray));					


ausblenden Delphi-Quelltext
1:
A_MyData := A_MyData_HilsArray; //Klappt auch nicht.					


Weiss jemand abhilfe?

Moderiert von user profile iconChristian S.: Delphi-Tags hinzugefügt
meolus
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 78

Gentoo, Debian, Win7 64-bit, WinXP
Delphi 2006 Prof., Delphi 2005 PE
BeitragVerfasst: Sa 14.10.06 17:00 
Du kannst einem Array, nicht dem anderen zuweisen, selbst wenn sie vom gleichen Typ sind. Du müsstest beide Arrays durchgehen und entsprechend die Elemente alle abgleichen.


Das Löschen in einem Array, kannste aber auch ganz einfach so realisieren:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
var
  MyArray: array of Integer; //ein dynamische Array


procedure DeleteIntArrayItem(pos: Integer);
var
  i: Integer;
begin
  for i := pos to Length(MyArray)-2 do begin //von "pos" bis vorletztes Element durchgehen...
    MyArray[i] := MyArray[i+1];
  end;
  SetLength(MyArray, Length(MyArray)-1);
end;


Habs nicht getestet, aber sollte so funktionieren.

_________________
Real programmers don't comment their code;
if it was hard to write, it should be hard to read.
daggit Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 56



BeitragVerfasst: So 15.10.06 13:27 
super danke.