导航

心动吧DELPHI网络书

自发研究:须要多维思想而且要想不可能为可能的人才能做到

« 求一简单函数,内详转换Word文档为RTF »

字符串和枚举类型转换

代码如下:

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

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

热文排行使用

本年排行使用

本月排行使用

网站分类

搜索内容

最新评论及回复

最近发表

所属分类下的文章

日历

Copyright ⊙ 2004-2009 心动吧 UrL:ABCXD.CoM All RiGhts Reserved