Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2011-04

GetEnumValue result type

2 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Leonardo M. Ramé

Hi, I'm having some trouble if I want to pass an enumerated type as a function parameter, when I get that type with GetEnumValue.

For example, if I have this type:

TMyType = (mtOne, mtTwo, mtThree);
var
  lMyType: TMyType;
begin
  lMyType := TMyType(GetEnumValue(TypeInfo(TMyType), 'mtTwo'));
  // lMyType is 1 instead of "mtTwo"
  // now I pass lMyType as a parameter in a function/procedure
  myFunction(lMyType);
end;

Shouln't lMyType be equal to mtTwo instead of 1?
How can I get mtTwo from GetEnumValue?

Leonardo M. Ramé
http://leonardorame.blogspot.com

Reply by email

Hans-Peter Diettrich
to Leonardo M. Ramé
Show quoted text 6 lines
TMyType = (mtOne, mtTwo, mtThree); var lMyType: TMyType; begin lMyType := TMyType(GetEnumValue(TypeInfo(TMyType), 'mtTwo')); // lMyType is 1 instead of "mtTwo"

How do you know? Since ord(mtTwo)=1, you seem to be fooled by the debugger.

DoDi

Reply by email