Autor Beitrag
Born-to-Frag
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1094

Win XP SP2, Win 2000 SP4
Delphi 7, 2k5
BeitragVerfasst: Di 23.05.06 19:14 
Hallo!

Also ich habe 2 Statische Array mit genau der selben größe:

ausblenden Delphi-Quelltext
1:
2:
P: Array [x..y] of XYZ;
S: Array [x..y] of XYZ;


gibt es ne Möglichkeit P S zuzuweisen, ohne eine Schleife?

S := P geht ja nichit


greetz

_________________
Theorie ist wenn man alles weiß, aber nichts funktioniert. Praxis ist wenn alles funktioniert, aber niemand weiß warum.
Microsoft vereint Theorie und Praxis: Nichts funktioniert und niemand weiß warum.
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10183
Erhaltene Danke: 1256

W10ent
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Di 23.05.06 19:38 
Moin!

Müsste mit
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
type
  TArray = array[0..1of Integer;
var
  P,S: TArray;

Move(P,S,SizeOf(TArray));

gehen. ;)

Aber sollte für deinen Zweck nicht das hier besser sein:
ausblenden Delphi-Quelltext
1:
PundS: array[0..1,x..y,x..y] of xyz;					

Jetzt kannst du mit PundS[0,i,j] auf P[i,j] und mit PundS[1,i,j] auf S[i,j] zugreifen. Das ganze über eine Auswahlvariable steuern und schon hast du beliebigen Zugriff. :D

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
Arno Nym
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 131



BeitragVerfasst: Di 23.05.06 19:38 
Hallo,
ob S := P funktioniert, hängt davon ab ob es sich bei den Array-Objekten um Grundtypen oder um Instanzen von Klassen handelt.
also z.B.
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
procedure TForm1.Button1Click(Sender: TObject);
var x,y : array[0..20of String;
begin
 x[2] := 'Hallo';
 y :=x;
 Showmessage(y[2]); //Ausgabe : 'Hallo'
 x[2] := 'neues Hallo';
 Showmessage(y[2]); //Ausgabe : 'Hallo'
end;

funktioniert, da Strings zu den Grundtypen gehören, und mit dem Zuweisungsoperator wirklich kopiert werden, also ist y[2] nach dem sich x[2] geändert hat immer noch 'Hallo'
anderes Bsp.
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
procedure TForm1.Button1Click(Sender: TObject);
var x,y : array[0..20of TForm;
begin
 x[2] := TForm.Create(self);
 x[2] := 'Hallo';
 y[2] := TForm.Create(self);
 y :=x;
 Showmessage(y[2]); //Ausgabe : 'Hallo'
 x[2] := 'neues Hallo';
 Showmessage(y[2]); //Ausgabe : 'Neues Hallo'
 y[2].Free;
 x[2].Free;
end;

funktioniert nicht, da mit dem Zuweisungsoperator nur ein Zeiger auf den Inhalt von x gesetzt wird.
Hier wirst du um eine Schleife wohl nicht drum rumkommen.

MFG, Arno Nym
Moderiert von user profile iconjasocul: Code-Tags durch Delphi-Tags ersetzt
Born-to-Frag Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1094

Win XP SP2, Win 2000 SP4
Delphi 7, 2k5
BeitragVerfasst: Di 23.05.06 20:33 
Danke Narses, hat geklappt!

War eigentlich nur eine allgemeine Frage, wollte es nicht benutzen ;)

Es ging aber darum, einer Lokalen Variable eine Globale zuzuweisen.

Etwa soetwas:
ausblenden Delphi-Quelltext
1:
2:
3:
if True then
  //P := globales Array 1
else // P := globales Array 2


Also danke nochmal, jetzt bin ich wieder schlauer :D


greetz

EDIT: @Arno: Es handelte sich um ein Array [1..7, 1..6] of Boolean und es hat nicht geklappt ohne Move().
Der Compiler meldete mir immer inkompatible Typen, egal ob P ein Array of Array of Boolean oder ein Array [1..7, 1..6] of Boolean war.

_________________
Theorie ist wenn man alles weiß, aber nichts funktioniert. Praxis ist wenn alles funktioniert, aber niemand weiß warum.
Microsoft vereint Theorie und Praxis: Nichts funktioniert und niemand weiß warum.