Autor Beitrag
Bennle
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 101

WinXP
Delphi 2007 Pro, C# (VS 2005)
BeitragVerfasst: Di 27.12.05 02:02 
Hallo,
Ich habe folgendes definiert:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
type TPosition = record
  Menge: Integer;
  Artikelnr: String;
  Artikel: String;
  Beschreibung: String;
  Preis: Real;
  Summe: Real;
  end;

var
   positionen: array of TPosition;

...
 positionen[0].Menge := 2;
  positionen[0].Artikelnr := '2222';
  positionen[0].Artikel := 'Nix';
  positionen[0].Beschreibung := 'xxx';
  positionen[0].Preis := 2.99;
  positionen[0].Summe := positionen[0].Menge * positionen[0].Preis;
...


Beim starten (also während der Laufzeit) tritt ein Fehler auf! (Bild)

Habe ich etwas falsch definiert?

MfG
Bennle
Einloggen, um Attachments anzusehen!
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: Di 27.12.05 02:24 
Du musst vor der Nutzung des Arrays dessen Größe mit SetLength festlegen.

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
Bennle Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 101

WinXP
Delphi 2007 Pro, C# (VS 2005)
BeitragVerfasst: Di 27.12.05 02:26 
user profile iconBenBE hat folgendes geschrieben:
Du musst vor der Nutzung des Arrays dessen Größe mit SetLength festlegen.


Aha, danke! Aber wie mach ich das ? :D
delfiphan
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2684
Erhaltene Danke: 32



BeitragVerfasst: Di 27.12.05 02:30 
z.B. so:
ausblenden Delphi-Quelltext
1:
SetLength(positionen, 5);					


(Dabei ist 5 die gewünschte Länge deines Arrays..)


Zuletzt bearbeitet von delfiphan am Di 27.12.05 02:37, insgesamt 1-mal bearbeitet
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: Di 27.12.05 02:33 
RTFM oder RTFDOH ...

ausblenden Delphi-Quelltext
1:
SetLength(ArrayVar, Len);					

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
Bennle Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 101

WinXP
Delphi 2007 Pro, C# (VS 2005)
BeitragVerfasst: Di 27.12.05 02:34 
Hallo,
Danke! Nun gehts!


MfG
Bennle
Ecki
Hält's aus hier
Beiträge: 2

Windows 2000/XP
Delphi 7
BeitragVerfasst: Sa 16.09.06 12:42 
Titel: Dynamische Arrays auch freigeben!
Hallo, der Tip ist ok, nur solltest Du am Ende deines Programmes dynamische Array´s auch wieder freigeben mit Setlength(positionen,0) , denn sonst bleibt der Speicher belegt.

Zwischendurch kannst du mit length(positionen) die reservierte Anzahl rausbekommen, mit high(positionen) das oberste element. Das ist praktisch für Schleifen for i := low(positionen) to high(positionen)
delfiphan
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2684
Erhaltene Danke: 32



BeitragVerfasst: Sa 16.09.06 18:01 
Ecki du bist nicht nur 3/4 Jahre zu spät sondern deine Antwort auch noch falsch ;)
Dyn. Arrays sind referenzgezählt und werden automatisch freigegeben. Genau wie die Strings auch.