Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Sonstige Fragen zu Delphi (https://www.delphipraxis.net/19-sonstige-fragen-zu-delphi/)
-   -   Delphi Case...of und Ordinal-Typ-Fehler? (https://www.delphipraxis.net/76295-case-und-ordinal-typ-fehler.html)

Bastler 1. Sep 2006 14:48


Case...of und Ordinal-Typ-Fehler?
 
Hallo zusammen;

Folgendes Problem:

Delphi-Quellcode:
procedure TForm1.bersichtWoche1Click(Sender: TObject);
var k:integer;
    tagg,tagh,tagm:string;

begin
tagg:=inttostr(DayofWeek(Yesterday));
tagg:=tagg+' ';

case tagg of
'1 ' : tagg:='Sonntag';
'2 ' : tagg:='Montag';
'3 ' : tagg:='Dienstag';
'4 ' : tagg:='Mittwoch';
'5 ' : tagg:='Donnerstag';
'6 ' : tagg:='Freitag';
'7 ' : tagg:='Samstag';
ens;
Panel2.caption:=tagg;

tagh:=inttostr(DayofWeek(now));
case tagh of
'1 ' : tagg:='Sonntag';
'2 ' : tagg:='Montag';
'3 ' : tagg:='Dienstag';
'4 ' : tagg:='Mittwoch';
'5 ' : tagg:='Donnerstag';
'6 ' : tagg:='Freitag';
'7 ' : tagg:='Samstag';
ens;
Panel3.caption:=tagg;

tagm:=inttostr(DayofWeek(Tomorrow));
case tagm of
'1 ' : tagg:='Sonntag';
'2 ' : tagg:='Montag';
'3 ' : tagg:='Dienstag';
'4 ' : tagg:='Mittwoch';
'5 ' : tagg:='Donnerstag';
'6 ' : tagg:='Freitag';
'7 ' : tagg:='Samstag';
ens;
Panel4.caption:=tagg;
Dann sagt mir der Compiler:

Zitat:

[Fehler] Unit1.pas(273): Ordinaltyp erforderlich
In der zeile wo das Case-Of steht, aber warum? ich bnutze Case-Ofs doch immer so...?
Bitte um Hilfe

Dax 1. Sep 2006 14:50

Re: Case...of und Ordinal-Typ-Fehler?
 
Du kannst nur Zahlen und Enumerationen in Case-Blöcken benutzen. Für Strings steht glaub ich irgendwas in der Codelib.. :gruebel:

Balu der Bär 1. Sep 2006 14:51

Re: Case...of und Ordinal-Typ-Fehler?
 
Wie wärs mit:
Delphi-Quellcode:
case StrToInt(tagg) of
1  : tagg:='Sonntag';
2  : tagg:='Montag';
3  : tagg:='Dienstag';
4  : tagg:='Mittwoch';
5  : tagg:='Donnerstag';
6  : tagg:='Freitag';
7  : tagg:='Samstag';
ens;
:gruebel:

Muetze1 1. Sep 2006 15:01

Re: Case...of und Ordinal-Typ-Fehler?
 
Zitat:

Zitat von Balu der Bär
Wie wärs mit:
Delphi-Quellcode:
case StrToInt(tagg) of
1  : tagg:='Sonntag';
2  : tagg:='Montag';
3  : tagg:='Dienstag';
4  : tagg:='Mittwoch';
5  : tagg:='Donnerstag';
6  : tagg:='Freitag';
7  : tagg:='Samstag';
ens;
:gruebel:

Würde nicht klappen, da er vor dem Case noch ein Leerzeichen nach der Zahl anhängt. Aber warum überhaupt von einem Ordinaltyp zu einem String und dann wieder zurück?

Delphi-Quellcode:
case DayofWeek(Yesterday) of
1  : tagg:='Sonntag';
2  : tagg:='Montag';
3  : tagg:='Dienstag';
4  : tagg:='Mittwoch';
5  : tagg:='Donnerstag';
6  : tagg:='Freitag';
7  : tagg:='Samstag';
end;

Balu der Bär 1. Sep 2006 15:02

Re: Case...of und Ordinal-Typ-Fehler?
 
Zitat:

Würde nicht klappen, da er vor dem Case noch ein Leerzeichen nach der Zahl anhängt.
Nagut, dass eine Leerzeichen könnte man auch per Delphi-Referenz durchsuchenDelete löschen. :stupid:

Aber deine Lösung wird wohl etwas passender sein. ;)

Bastler 1. Sep 2006 15:04

Re: Case...of und Ordinal-Typ-Fehler?
 
Danke Muetze1 - scheint so als hätte ichn Blackout gehabt...
:coder2:

Naja danke euch allen...

RavenIV 1. Sep 2006 15:39

Re: Case...of und Ordinal-Typ-Fehler?
 
wie gefällt Dir:
Delphi-Quellcode:
tagm:=inttostr(DayofWeek(Tomorrow));
case tagm [1] of
  '1' : tagg:='Sonntag';
  '2' : tagg:='Montag';
  '3' : tagg:='Dienstag';
  '4' : tagg:='Mittwoch';
  '5' : tagg:='Donnerstag';
  '6' : tagg:='Freitag';
  '7' : tagg:='Samstag';
end;

Khabarakh 1. Sep 2006 16:26

Re: Case...of und Ordinal-Typ-Fehler?
 
Na sicher nicht besser als Mützes Lösung.

Flocke 1. Sep 2006 17:10

Re: Case...of und Ordinal-Typ-Fehler?
 
Delphi hat doch ein Array mit den Wochentagsnamen in SysUtils.pas, also ist's so wohl am einfachsten:
Delphi-Quellcode:
procedure TForm1.bersichtWoche1Click(Sender: TObject);
begin
  Panel2.caption := LongDayNames[DayOfWeek(Yesterday)];
  Panel3.caption := LongDayNames[DayOfWeek(Now)];
  Panel4.caption := LongDayNames[DayOfWeek(Tomorrow)];
end;


Alle Zeitangaben in WEZ +1. Es ist jetzt 02:11 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz