Autor Beitrag
hansg
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 168

Win XP Professional SP3, Vista Ultimate 32 SP1
Delphi 6 Professional
BeitragVerfasst: Mi 18.04.07 17:22 
Hallo zusammen,

ich ich suche für folgendens Problem eine Lösung:

Ich bekommme einen Zahlencode (ca. 200 Stück).
Jedem Code möchte ich einen Text zuordnen.
Welche Möglichkeiten gibt es da so.
ausblenden Delphi-Quelltext
1:
2:
3:
  if code = 1 then Text:=...
  if code = 2 then Text:=...
  if code = 3 then Text:=...


wäre eine Lösung, eine andere die

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
  case code of
  1: begin
       Text:=...
     end;
  2: begin
       Text:=...
     end;
  3: begin
       Text:=...
     end;
  end;

ist mir irgenwie aber alles was umständlich, kann man sowas nicht einfacher definieren und auswerten?

_________________
Gruß Hans
ConditionZero
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 190

Win XP
Delphi 7 PE, C++ (Dev-C++), HTML+PHP (Dreamweaver MX), JavaScript(MS FrontPage)
BeitragVerfasst: Mi 18.04.07 17:41 
case ist (in meinen augen zumindest^^) das kürzeste was du da machen kannst.
Marc.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1876
Erhaltene Danke: 129

Win 8.1, Xubuntu 15.10

BeitragVerfasst: Mi 18.04.07 17:54 
Stehen die Texte schon zur Entwicklungszeit fest oder erst zur Laufszeit?
Und gehören bestimmte Texte fest zu bestimmten Weten von Code?
Dann würd ichs mit ner Stringlist probieren:
ausblenden Delphi-Quelltext
1:
Text := SL.ValueFromIndex[code];					

So etwas in der Art ;)
Jakob Schöttl
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 929
Erhaltene Danke: 1


Delphi 7 Professional
BeitragVerfasst: Mi 18.04.07 18:38 
Bei einer StringList müsstest du den Inhalt zwar auch zur Laufzeit (zB.OnCreate) zuweisen, aber nur einmal hald.
Und denke dran, der Index geht bei 0 los, also müsste es in deinem Fall heißen:
ausblenden Delphi-Quelltext
1:
Text := StringList.Strings[code -1];