Autor Beitrag
Niko S.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 566
Erhaltene Danke: 10

Win 7, Ubuntu
Lazarus, Turbo Delphi, Delphu 7 PE
BeitragVerfasst: Mo 02.08.10 20:11 
Hi Leute,

also ich versuche eine Array zu deklarieren, die zur Laufzeit konstant ist aber im code optisch variabel ist.
Das ganze beruht auf folgender Idee:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
type
  TVitals = (
    vitHP = 1,
    vitMP,
    vitSP,
    vital_count
    );
...
var
  vital: array[1..(vital_count-1)] of Byte;


Sowas mag Delphi aber nicht.
Gibts andere möglichkeiten (außer Dyn Array)?

Gruß
Niko
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8554
Erhaltene Danke: 480

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: Mo 02.08.10 20:21 
Das würde ich mit einer zusätzlichen Konstante machen
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
type
  TVitals = (
    vitHP = 1,
    vitMP,
    vitSP
   );
const vital_count = 3// muss natürlich mit TVitals konsistent sein

var
  vital: array[1..vital_count] of Byte;

_________________
We are, we were and will not be.
Martok
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 3661
Erhaltene Danke: 604

Win 8.1, Win 10 x64
Pascal: Lazarus Snapshot, Delphi 7,2007; PHP, JS: WebStorm
BeitragVerfasst: Mo 02.08.10 20:48 
Also für mich klingt das eher nach sowas:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
type
  TVitals = (
    vitHP = 1,
    vitMP,
    vitSP
    );
...
var
  vital: array[TVitals] of Byte;

_________________
"The phoenix's price isn't inevitable. It's not part of some deep balance built into the universe. It's just the parts of the game where you haven't figured out yet how to cheat."
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19339
Erhaltene Danke: 1752

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Mo 02.08.10 22:06 
Um mal den Faden noch weiterzuspinnen :mrgreen:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
type
  TVitals = (vitHP, vitMP, vitSP);

const
  Vitals: array[TVitals] of string = ('Haltbare Packung''Miefige Packung''Sonderbare Packung');

// und im Code:
var
  MyVital: TVitals;
...
ShowMessage(Vitals[MyVital]);
Niko S. Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 566
Erhaltene Danke: 10

Win 7, Ubuntu
Lazarus, Turbo Delphi, Delphu 7 PE
BeitragVerfasst: Di 03.08.10 06:55 
Dankeschön =)
Manchmal sind die Dinge einfacher als man denkt.
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: Di 03.08.10 10:09 
auch wenn martoks und jaenickes lösung ein array von 0..x machen statt 1..x-1 (bei gleichem x)

aber darum ist es wichtig, hinzuschreiben, wofür man was braucht.