太阳火 的办法是可行的:
function CountCharSet(ASet: TSysCharSet): Integer;
var
c: Char;
begin
Result := 0;
for c := Low(Char) to High(Char) do
if c in ASet then
Inc(Result);
end;
不过如果这个集合属于一个对象的话,就方便点,传入对象和集合属性的字符串名:
function CountSetOfClass(Obj: TObject
SetName: string): Integer;
var
TypInfo: PTypeInfo;
TypData: PTypeData;
SetStr: string;
SetList: TStringList;
begin
TypInfo := TypeInfo(aaa);
TypData := GetTypeData(typinfo);
SetList := TStringList.Create;
SetStr := GetSetProp(Obj, SetName);
Result := ExtractStrings([','], [], PChar(SetStr), SetList);
SetList.Free;
end;