Thema: Delphi Frage zu GetEnumValue

Einzelnen Beitrag anzeigen

Benutzerbild von mirage228
mirage228

Registriert seit: 23. Mär 2003
Ort: Münster
3.750 Beiträge
 
Delphi 2010 Professional
 
#3

Re: Frage zu GetEnumValue

  Alt 29. Jul 2004, 09:33
Zitat von Niels:
Hallo,

hier mal ein Beispiel um meine Frage verständlicher zu machen:

Delphi-Quellcode:
type
  TMeinTyp = (mtA, mtB, mtC);

procedure bla(x: string);
var
  hilf: TMeinTyp;
begin
  hilf := TMeinTyp(GetEnumValue(TypeInfo(TMeinTyp), x));
  ...
end;
Mein Problem liegt jetzt darin, wenn x weder mtA, noch mtB oder mtC ist. Wenn ich Debugge steht da:
Code:
hilf = (out of bound) -1
Wie kann ich jetzt abfragen ob das nun -1 ist.
if hilf = -1 then funktioniert nicht, da -1 nicht vom Typ TMeinTyp ist? Der einzige wichtige Fall ist aber, wenn hilf = -1.

mfg Niels
Hoi,

proviers mal so

Delphi-Quellcode:
procedure bla(const x: string);
var
  hilf: Integer;
  wert: TMeinTyp;
begin
  hilf := GetEnumValue(TypeInfo(TMeinTyp), x);
  if hilf = -1 then
     ... else
  wert := TMeinTyp(hilf);
end;
mfG
mirage228
David F.

May the source be with you, stranger.
PHP Inspection Unit (Delphi-Unit zum Analysieren von PHP Code)
  Mit Zitat antworten Zitat