Autor Beitrag
Schweini31
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 26



BeitragVerfasst: Mi 16.01.08 15:34 
Ich entschudlige mich vornerein schonmal für die Anfängerfrage:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
case lbLevel.caption of
  'Level 1':lbNot.Caption:='15';
  'Level 2':lbNot.Caption:='30';
  end;


Was mache ich denn falsch?

Fehler:

Ordinaltyp erforderlich

und

2x Konstantenausdruck erforderlich

Ich hoffe ich wende es richtig an(also überhaupt den Sinn).
Wo ist denn der Fehler?

Schweini


Moderiert von user profile iconChristian S.: Topic aus VCL (Visual Component Library) verschoben am Mi 16.01.2008 um 15:38
zuma
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 660
Erhaltene Danke: 21

Win XP, Win7, Win 8
D7 Enterprise, Delphi XE, Interbase (5 - XE)
BeitragVerfasst: Mi 16.01.08 15:38 
Hallo,

ein Case geht nicht mit Strings (Fehler Ordinaltyp)

case geht z.b. so:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
zahl := 3;
case zahl of
 1 : Machwasbeieins;
 2 : achwasbeizwei;
else
 machwasbeinichtabgefangenerzahl
end;


Moderiert von user profile iconChristian S.: Delphi-Tags hinzugefügt

_________________
Ich habe nichts gegen Fremde. Aber diese Fremden sind nicht von hier! (Methusalix)
Warum sich Sorgen ums Leben machen? Keiner überlebts!
Christian S.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 20451
Erhaltene Danke: 2264

Win 10
C# (VS 2019)
BeitragVerfasst: Mi 16.01.08 15:40 
Hallo!

Die case-Anweisung funktioniert mit Ordinaltypen, das sind Typen, die man aufzählen kann. Also z.B. Integer (1,2,3,4,...), Char('a','b','c', ...), usw. Ein String ist nicht aufzählbar, daher geht das nicht.

Grüße
Christian

_________________
Zwei Worte werden Dir im Leben viele Türen öffnen - "ziehen" und "drücken".
Schweini31 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 26



BeitragVerfasst: Mi 16.01.08 15:43 
Ok danke!

Gibts eine Alternative dazu in diesem Fall? Mit if ist es umständlich.

Was ich probiere ist ja klar. oder?

Schweini
Calculon
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 676

Win XP Professional
Delphi 7 PE, Delphi 3 PRO
BeitragVerfasst: Mi 16.01.08 15:48 
Installier' die DLangExtensions und nutze case:

Bsp. aus der Doku::
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
procedure TFormExecCmd.btnExecuteClick(Sender: TObject);
begin
  case string(edtCommand.Text)of
    'Hallo', 'Hello':
      ShowMessage('Hallo');
    'Exit':
      Close;
  else
    ShowMessage('Unknown command: ' + edtCommand.Text);
  end;
end;


Gruß

Calculon
--

_________________
Hallo Mutti
Blackheart666
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2195

XP
D3Prof, D6Pers.
BeitragVerfasst: Mi 16.01.08 15:50 

_________________
Blackheart666
Der Irrsinn ist bei Einzelnen etwas Seltenes, - aber bei Gruppen, Parteien, Völkern, Zeiten die Regel. (Friedrich Nietzsche)
Kroko
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1284

W98 W2k WXP
Turbo D
BeitragVerfasst: Mi 16.01.08 16:00 
fülle ein TStringList mit den case-Strings und ermittle den Index per TStringList.IndexOf(SearchString);

_________________
Die F1-Taste steht nicht unter Naturschutz und darf somit regelmäßig und oft benutzt werden! oder Wer lesen kann, ist klar im Vorteil!