Autor Beitrag
Bomania
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 139

Win XP

BeitragVerfasst: Sa 15.02.03 18:57 
Hallo,

ich habe in der Hilfe keinerlei Hinweis für eine Switch-Funktion wie unter C oder eine Select-Case-Funktion wie unter VB gefunden. Gibt es sowas unter Delphi denn nicht??

Gruß,
Björn
AndyB
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1173
Erhaltene Danke: 14


RAD Studio XE2
BeitragVerfasst: Sa 15.02.03 19:04 
Doch:
ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
var X: Integer;
X := 10;
case X of
    1: begin
         ShowMessage('Eins');
       end;
   10: begin
         ShowMessage('Zehn');
       end;
  100: begin
         ShowMessage('Hundert');
       end;
  else
  begin
    ShowMessage('Kenn ich nicht!');
  end;
end;

_________________
Ist Zeit wirklich Geld?
Bomania Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 139

Win XP

BeitragVerfasst: Sa 15.02.03 19:16 
Danke, und wenn ich mehrere Fälle gleichzeitig (zusammen) abfragen möchte?

ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
case txt_Text.text of
  65 To 90, 97 To 122:
  begin
    ...
  end;
  48 to 57:
.......
AndyB
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1173
Erhaltene Danke: 14


RAD Studio XE2
BeitragVerfasst: Sa 15.02.03 20:04 
Dann musst du die einzelnen Werte mit Komma trennen:
ausblenden Quelltext
1:
2:
3:
4:
case X of
  1, 3, 5: begin end;
  6..100: begin end; // 6 bis 100
end;


case of entspricht der switch-Anweisung und nicht dem Select Case. Aus diesem Grund kannst du keine Strings damit abfragen.

_________________
Ist Zeit wirklich Geld?
Klabautermann
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Veteran
Beiträge: 6366
Erhaltene Danke: 60

Windows 7, Ubuntu
Delphi 7 Prof.
BeitragVerfasst: Sa 15.02.03 20:05 
Hallo,
Bomania hat folgendes geschrieben:
Danke, und wenn ich mehrere Fälle gleichzeitig (zusammen) abfragen möchte?

dann verwendest du die unter Delphi übliche mengenschreibweise nur ohne die Eckigen Klammern:
ausblenden Quelltext
1:
2:
3:
4:
CASE X OF
  1,3 : ShowMessage('eins oder Drei');
  2,4..7: Showmessage('zwei oder irgendwas zwischen 4 & 7.');
END;


Gruß
Klabautermann
maximus
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 896

Win XP, Suse 8.1
Delphi 4/7/8 alles prof
BeitragVerfasst: Sa 15.02.03 20:05 
hi!
ausblenden Quelltext
1:
2:
3:
case x of
  1, 2, 5..9 : doSomething;
end;
maximus
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 896

Win XP, Suse 8.1
Delphi 4/7/8 alles prof
BeitragVerfasst: Sa 15.02.03 20:07 
*lol* Alle druff! 3fach hält besser :D
Bomania Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 139

Win XP

BeitragVerfasst: Sa 15.02.03 21:36 
Danke euch allen! :)