在Delphi中可以将字符串转换为集合 [英] In Delphi can a string be converted to a set
本文介绍了在Delphi中可以将字符串转换为集合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
例如
Font.Style = StringToSet('[fsBold, fsUnderline]');
当然,其中需要一些 typeinfo 的东西,但你明白了.我正在使用 Delphi 2007.
of course there would need to be some typeinfo stuff in there, but you get the idea. I'm using Delphi 2007.
推荐答案
检查此代码,与您建议的语法不完全相同,但可以从字符串设置集合的值.
check this code, is not exactly the same syntax which you propose , but works setting the value of a set from a string.
uses
TypInfo;
procedure StringToSet(Const Values,AProperty:string;Instance: TObject);
begin
if Assigned(GetPropInfo(Instance.ClassInfo, AProperty)) then
SetSetProp(Instance,AProperty,Values);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
StringToSet('[fsBold, fsUnderline, fsStrikeOut]','Style',Label1.Font);
end;
这篇关于在Delphi中可以将字符串转换为集合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文