偶也遇到这个头痛的问题,来不及研究了,只能这样,我:(Function GetAnchors(Control : TControl ; Parama : String ) : TAnchors; begin if Control.Anchors = [akLeft] then ResultStr := #39+'[akLeft]'+#39 else if Control.Anchors = [akTop] then ResultStr := #39+'[akTop]'+#39 else if Control.Anchors = [akRight] then ResultStr := #39+'[akRight]'+#39 else if Control.Anchors = [akBottom] then ResultStr := #39+'[akBottom]'+#39 else if Control.Anchors = [akLeft,akTop] then ResultStr := #39+'[akLeft,akTop]'+#39 else if Control.Anchors = [akLeft,akRight] then ResultStr := #39+'[akLeft,akRight]'+#39 else if Control.Anchors = [akLeft,akBottom] then ResultStr := #39+'[akLeft,akBottom]'+#39 else if Control.Anchors = [akLeft,akTop,akRight] then ResultStr := #39+'[akLeft,akTop,akRight]'+#39 else if Control.Anchors = [akLeft,akTop,akBottom] then ResultStr := #39+'[akLeft,akTop,akBottom]'+#39 else if Control.Anchors = [akLeft,akRight,akBottom] then ResultStr := #39+'[akLeft,akRight,akBottom]'+#39 else if Control.Anchors = [akLeft,akTop] then ResultStr := #39+'[akLeft,akTop]'+#39 else if Control.Anchors = [akLeft,akTop,akRight] then ResultStr := #39+'[akLeft,akTop,akRight]'+#39 else if Control.Anchors = [akLeft,akTop,akRight,akBottom] then ResultStr := #39+'[akLeft,akTop,akRight,akBottom]'+#39 ..... end;
case tt of aa:astr:='aa'; bb:astr:='bb'; cc:astr:='cc'; ...... end;
getenumname(typeinfo(enumtype),ord(enum));
uses typinfo; var i:enumtype; begin for i:=low(enumtype) to high(enumtype) do showmessag(getenumname(typeinfo(enumtype),ord(i))); end;
//type TAnchors = set of TAnchorKind; //type TAnchorKind = (akTop, akLeft, akRight, akBottom); uses TypInfo; var i:TAnchorKind ; begin for i:=low(TAnchorKind ) to high(TAnchorKind ) do if i in Control.Anchors then showmessag(getenumname(typeinfo(TAnchorKind ),i)); end;
begin
if Control.Anchors = [akLeft] then
ResultStr := #39+'[akLeft]'+#39
else if Control.Anchors = [akTop] then
ResultStr := #39+'[akTop]'+#39
else if Control.Anchors = [akRight] then
ResultStr := #39+'[akRight]'+#39
else if Control.Anchors = [akBottom] then
ResultStr := #39+'[akBottom]'+#39 else if Control.Anchors = [akLeft,akTop] then
ResultStr := #39+'[akLeft,akTop]'+#39
else if Control.Anchors = [akLeft,akRight] then
ResultStr := #39+'[akLeft,akRight]'+#39
else if Control.Anchors = [akLeft,akBottom] then
ResultStr := #39+'[akLeft,akBottom]'+#39 else if Control.Anchors = [akLeft,akTop,akRight] then
ResultStr := #39+'[akLeft,akTop,akRight]'+#39
else if Control.Anchors = [akLeft,akTop,akBottom] then
ResultStr := #39+'[akLeft,akTop,akBottom]'+#39 else if Control.Anchors = [akLeft,akRight,akBottom] then
ResultStr := #39+'[akLeft,akRight,akBottom]'+#39 else if Control.Anchors = [akLeft,akTop] then
ResultStr := #39+'[akLeft,akTop]'+#39
else if Control.Anchors = [akLeft,akTop,akRight] then
ResultStr := #39+'[akLeft,akTop,akRight]'+#39
else if Control.Anchors = [akLeft,akTop,akRight,akBottom] then
ResultStr := #39+'[akLeft,akTop,akRight,akBottom]'+#39
.....
end;
aa:astr:='aa';
bb:astr:='bb';
cc:astr:='cc';
......
end;
var
i:enumtype;
begin
for i:=low(enumtype) to high(enumtype) do
showmessag(getenumname(typeinfo(enumtype),ord(i)));
end;
usesTypInfo;typeTTest = (a, b, c, d, haha, yeah); procedure TForm1.Button1Click(Sender: TObject);varti: PTypeInfo;td: PTypeData;i: Integer;beginti := TypeInfo(TTest);td := GetTypeData(ti);for i := td^.MinValue to td^.MaxValue doListBox1.Items.Add(GetEnumName(ti, i));end;
对 Control.Anchors 怎么不行拉?
//type TAnchorKind = (akTop, akLeft, akRight, akBottom);
uses TypInfo;
var
i:TAnchorKind ;
begin
for i:=low(TAnchorKind ) to high(TAnchorKind ) do
if i in Control.Anchors then
showmessag(getenumname(typeinfo(TAnchorKind ),i));
end;