Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Object-Pascal / Delphi-Language (https://www.delphipraxis.net/32-object-pascal-delphi-language/)
-   -   Delphi Frage zu GetEnumValue (https://www.delphipraxis.net/26771-frage-zu-getenumvalue.html)

Niels 29. Jul 2004 08:04


Frage zu GetEnumValue
 
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.
Delphi-Quellcode:
if hilf = -1 then
funktioniert nicht, da -1 nicht vom Typ TMeinTyp ist? Der einzige wichtige Fall ist aber, wenn hilf = -1.

mfg Niels

Robert Marquardt 29. Jul 2004 09:20

Re: Frage zu GetEnumValue
 
Was steht denn in x drin?

mirage228 29. Jul 2004 09:33

Re: Frage zu GetEnumValue
 
Zitat:

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.
Delphi-Quellcode:
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

Niels 29. Jul 2004 21:06

Re: Frage zu GetEnumValue
 
Hi,

danke ...funktioniert prima. Hätte ich eigentlich auch selbst drauf kommen können :duck:

mfg Niels


Alle Zeitangaben in WEZ +1. Es ist jetzt 02:37 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