代码如下:
| theStringname := GetEnumName(Typeinfo(TAlignment),Ord(label1.Alignment)); label1.Alignment := TAlignment(GetEnumValue(TypeInfo(TAlignment),theStringname)); //////////////////////////////// type colours=(red,blue,green) var colour: colours begin colour:='red'; end; function ColoursToString (C : Colours) : String begin Result := GetEnumName (TypeInfo (Colours), Ord (C)); end; function StringToColours (S : String) : Colours; var IntVal : Integer; begin IntVal := GetEnumValue (TypeInfo (Colours), S); if IntVal = -1 then raise Exception.Create ('Invalid string'); Result := Colours (IntVal); end; |
原创文章如转载,请注明:转载自心动吧DELPHI网络书 [ http://www.abcxd.com/delphi/ ]
本文链接地址:http://www.abcxd.com/delphi/abcxddelphi/delphiJIANHUAN/52.html