Autor Beitrag
Janus
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 33



BeitragVerfasst: Do 13.03.03 18:37 
Hallo Leute, ich habe in der Dokumentation keine Angaben über array funktionen gefunden. Gibt es eine Möglichkeite, ein Array mit einem bestimmten Standardwert zu füllen ?

z.B.

ausblenden Quelltext
1:
2:
3:
4:
arr: array of Integer;

SetLength(arr,100);
setmem(arr,0); // so was in der Art


Gruss Janus

Moderiert von user profile iconMarc: Code-Tag eingefügt. Beitrag verschoben.

_________________
Don't give in the hate, that leaves to the dark side of the force !!!
MSCH
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1448
Erhaltene Danke: 3

W7 64
XE2, SQL, DevExpress, DevArt, Oracle, SQLServer
BeitragVerfasst: Do 13.03.03 18:49 
Hi,
ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
var A: Array[0..234] of Char;
      B: Array of Integer;
FillChar(A,Sizeof(A),'Z');
...
SetLength(B,1000);
FillChar(B,1000,123);
...

grüße
MSCH

Moderiert von user profile iconMarc: Code-Tag eingefügt.
Andreas Pfau
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 997



BeitragVerfasst: Fr 14.03.03 13:25 
TILT! Access Violation. Warum? Ein dynamischer Array ist ein dynamisch zugewiesener Speicherblock, und keine Variable!!!

Lösung: Auf das erste Element zugreifen (Hat die selbe Adresse):
ausblenden Quelltext
1:
2:
3:
4:
var B: Array of Integer;
begin
  SetLength(B,1000);
  FillChar(B[0],Length(B),123);

_________________
Life is a bad adventure, but the graphic is really good!
Motzi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2931

XP Prof, Vista Business
D6, D2k5-D2k7 je Prof
BeitragVerfasst: Fr 14.03.03 13:45 
Andreas Pfau hat folgendes geschrieben:
TILT! Access Violation. Warum? Ein dynamischer Array ist ein dynamisch zugewiesener Speicherblock, und keine Variable!!!

Lösung: Auf das erste Element zugreifen (Hat die selbe Adresse):

Soweit richtig.. aber:
Zitat:
ausblenden Quelltext
1:
2:
3:
4:
var B: Array of Integer;
begin
  SetLength(B,1000);
  FillChar(B[0],Length(B),123);

Das wird nicht gehen.. überleg mal: du hast einen Array of Integer. Ein Integer ist 4 Bytes groß, und der array enthält 1000 Elemente. Die Größe beträgt daher 4*1000 Bytes und nicht nur 1000 (Length(array))

FillChar kann dazu verwendet werden, um jedem Byte eines Speicherblocks denselben Wert zuzuweisen (für 0 gibts sogar eine eigene Funktion: ZeroMemoy). Aber in diesem Fall funktioniert das nicht, da bei einem Integer mit dem Wert 123 nicht alle Bytes gleich sind.

In diesem Fall wäre also eine for-schleife angebracht!

_________________
gringo pussy cats - eef i see you i will pull your tail out by eets roots!
Andreas Pfau
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 997



BeitragVerfasst: Fr 14.03.03 14:15 
Äh... du hast Recht :oops:

Aber @MSCH hat ja damit angefangen :wink:

Also: Wenn's ein Byte- oder Char-Array wäre, müsste man trotzdem auf das erste element zugreifen. Oder 'ne schleife erstellen.[/code]

_________________
Life is a bad adventure, but the graphic is really good!