Autor Beitrag
Flamefire
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1207
Erhaltene Danke: 31

Win 10
Delphi 2009 Pro, C++ (Visual Studio)
BeitragVerfasst: Do 30.09.10 14:43 
Ich will die Länge eines Arrays über eine konstante festlegen.
Also sowas:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
const mySize:Integer=99;

type
 TFoo=class(TObject)
 private
    FArray:Array[mySize] of Integer;
 end;


Da meckert Delphi aber, "Konstante oder Typbezeichner erwartet".
Ich könnte aber schwören, das ging mal... Da Delphi Konstanten doch inlined (Nicht wie bei C als Read-Only-Variable)

Wie mache ich das?


Zuletzt bearbeitet von Flamefire am Do 30.09.10 14:48, insgesamt 1-mal bearbeitet
iKilledKenny
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 394
Erhaltene Danke: 8

Win XP
D5 Prof, C# Express 2005
BeitragVerfasst: Do 30.09.10 14:44 
Das sollte mit einem dynamischen Array und SetLength gehen.
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8554
Erhaltene Danke: 481

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: Do 30.09.10 14:46 
Du musst schon untere und obere Grenze angeben.
ausblenden Delphi-Quelltext
1:
 FArray:Array[0..mySize] of Integer;					

sollte gehen. Oder mit Aufzählungstypen arbeiten.

_________________
We are, we were and will not be.

Für diesen Beitrag haben gedankt: BenBE
Flamefire Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1207
Erhaltene Danke: 31

Win 10
Delphi 2009 Pro, C++ (Visual Studio)
BeitragVerfasst: Do 30.09.10 14:48 
Ok, obere und untere Grenze war ein Fehler.
Der 2.:
Geht:
ausblenden Delphi-Quelltext
1:
const mySize=99;					

Geht Nicht:
ausblenden Delphi-Quelltext
1:
const mySize:Integer=99;					
elundril
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 3747
Erhaltene Danke: 123

Windows Vista, Ubuntu
Delphi 7 PE "Codename: Aurora", Eclipse Ganymede
BeitragVerfasst: Do 30.09.10 14:55 
user profile iconFlamefire hat folgendes geschrieben Zum zitierten Posting springen:
ausblenden Delphi-Quelltext
1:
const mySize:Integer=99;					


weil das eine typisierte konstante ist. Typisierte Konstanten können zur Laufzeit ihren Wert ändern, demnach sowas wie initialisierte Variablen in Java oder C++.

lg elundril

_________________
This Signature-Space is intentionally left blank.
Bei Beschwerden, bitte den Beschwerdebutton (gekennzeichnet mit PN) verwenden.

Für diesen Beitrag haben gedankt: BenBE
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: Do 30.09.10 15:39 
user profile iconGausi hat folgendes geschrieben Zum zitierten Posting springen:
Du musst schon untere und obere Grenze angeben.
ausblenden Delphi-Quelltext
1:
 FArray:Array[0..mySize-1of Integer;					

sollte gehen. Oder mit Aufzählungstypen arbeiten.

UND die Offsets richtig initialisieren...

Ansonsten die Bemerkung bzw. typisierter Konstanten beachten.

_________________
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.