Autor Beitrag
digi_c
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1905

W98, XP
D7 PE, Lazarus, WinAVR
BeitragVerfasst: Fr 14.04.06 12:27 
Moinsen Community!

Ich meine das ich es schonmal gesehen habe(in C?), das man ein statisches Array automatisch so groß deklarieren konnte, dass alle Elemente einer typenumeration da rein passen.

Es geht mir um folgendes:
ausblenden Delphi-Quelltext
1:
2:
type 
  TStates=(sValid,sInvalid,sInspected,...);


...und nun möchte ich ein statisches Stringarray zum ausgeben des Status haben.
ausblenden Delphi-Quelltext
1:
2:
const
  States: Array[0..n] of string =('Gültig',Ungültig,'Geprüft'...);


Nun möchte ich das Stringarray aber so haben das es so viele Elemente die der Typ Möglichkeiten hat hat.
Dadurch würde mich der Compiler daran erinnern auch ein neues Stringelement hinzuzufügen...

ausblenden Delphi-Quelltext
1:
2:
const
  States: Array[low(TStates)..high(TStates)] of string =('Gültig',Ungültig,'Geprüft'...);

...funktioniert aber nicht, genausowenig wie ord() oder length() oder sizeof() der Typ ist ebend kein Array :(

Wie/Geht das?
mkinzler
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 4106
Erhaltene Danke: 13


Delphi 2010 Pro; Delphi.Prism 2011 pro
BeitragVerfasst: Fr 14.04.06 12:30 
Nimm doch einen dynmischen Array und passe nur dessen Größe wie benötigt an.

_________________
Markus Kinzler.
digi_c Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1905

W98, XP
D7 PE, Lazarus, WinAVR
BeitragVerfasst: Fr 14.04.06 12:56 
Dann würde mir aber der Vorteil verloren gehen das mich der Compiler darauf aufmerksam macht :(
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: Fr 14.04.06 18:32 
Probier's mal so:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
type 
  TStates=(sValid,sInvalid,sInspected,{...});
const
  States: Array[TStates] of string = ('Gültig','Ungültig','Geprüft',{...});


MfG,
BenBE.

_________________
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.
digi_c Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1905

W98, XP
D7 PE, Lazarus, WinAVR
BeitragVerfasst: Sa 15.04.06 10:45 
Wunderbar! Danke, ich habe immer probiert, die Grenzen zu definieren, wär nicht drauf gekommen, dass es so einfach ist.