A) Several correlations used first
• Remove characters in the 挙 挙 中 中 (Integer) with "GetEnumValue".
Function GetEnumValue (TypeInfo: PtypeInfo; Const Name: String): Integer;
· Remove the name of the enumeration in the enumeration in the "GetEnumName".
Function genumname (TypeInfo: PtypeInfo; Value: integer): String;
· Insert an element into the set with "include", equivalent to s: = s [i]
Procedure Include (Var S: set of t; i: t);
2)
In order to reveal the content in the collection, the "TMSGDLGBUTTONS" collection existing in Delphi is an example.
· Insert a string into a collection.
Such as: 'mbyes, mbno, mbok, mbcancel, mbignore' → [MByes, MBNO, MBOK, MBCANCEL, MbIgnore]
• The contents in the collection are expressed in the form of a string.
Such as: [MByes, MBNO, Mbok, Mbcancel, Mbignore] → 'mbyes, mbno, mbok, mbcancel, mbignore'
Click here
Show code
// "TMSGDLGBUTTONS" definition in Delphi
Type
TMSGDLGBTN = (mbyes, mbno, mbok, mbcancel, mbabort, mbretry, mbignore, mball, mbnotoall, mbyestoall, mbhelp);
TMSGDLGBUTTONS = set of tMSGDLGBTN;
VAR
FORM1: TFORM1;
IMPLEMentation
{$ R * .dfm}
Uses
Typinfo;
// String → Collection
Procedure TFORM1.BUTTON1CLICK (Sender: TOBJECT);
VAR
Strlist: tstringlist;
Msgdlgbtns: TMSGDLGBUTTONS;
Str: string;
i: integer;
Begin
Str: = 'mbyes, mbno, mbok, mbcancel, mbignore';
Strlist: = TSTRINGLIST.CREATE;
Try
Extractstrings ([','], [''], PCHAR (STR), STRLIST);
For i: = 0 to strlist.count-1 do
Include (Msgdlgbtns, TMSGDLGBTN (GetEnumValue (TypeInfo (TMSGDLGBTN), Strlist.Strings [i]))))))
Messagedlg ('confirm', MTConfirmation, msgdlgbtns, 0);
Finally
Strlist.free;
END;
END;
// Collection → String
Procedure TFORM1.BUTTON2CLICK (Sender: TOBJECT);
VAR
Msgdlgenum: TMSGDLGBTN;
Msgdlgbtns: TMSGDLGBUTTONS;
Str: string;
Begin
Msgdlgbtns: = [mbyes, mbno, mbok, mbcancel, mbignore];
For msgdlgenum: = low (tmsgdlgbtn) to high (tmsgdlgbtn) DO
IF msgdlgenum in msgdlgbtns trenstr: = STR GETENUMNAME (TypeInfo (TMSGDLGBTN), ORD (MSGDLGENUM)) ','
ShowMessage (STR);
END;
Note: This program is passed on Delphi7.