Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to Convert a string to a set and vice versa using RTTI Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
29-Jul-04
Category
Object Pascal
Language
Delphi 3.x
Views
189
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Peter Below

Given a string like '[mbOk, mbCancel]', what is a simple way to use the routines in 
TypInfo to produce the corresponding set?

Answer:

1   uses
2     TypInfo;
3   
4   function ButtonStringToSet(const S: string): TMsgDlgButtons;
5   var
6     Temp: TStringlist;
7     I: Integer;
8     N1, N2: Integer;
9   begin
10    Result := [];
11    N1 := Pos('[', S);
12    N2 := Pos(']', S);
13    if N2 = 0 then
14      N2 := Length(S) + 1;
15    Assert(N2 > N1);
16    Temp := TStringlist.Create;
17    try
18      Temp.Commatext := Copy(S, N1 + 1, N2 - N1 - 1);
19      for i := 0 to Temp.Count - 1 do
20        Include(Result, TMsgDlgBtn(TypInfo.GetEnumValue(TypeInfo(TMsgDlgBtn),
21          Trim(Temp[I]))));
22    finally
23      Temp.Free;
24    end;
25  end;
26  
27  function SetToButtonString(Buttons: TMsgDlgButtons): string;
28  var
29    Temp: TStringlist;
30    Btn: TMsgDlgBtn;
31  begin
32    Temp := TStringlist.Create;
33    try
34      for Btn := Low(Btn) to High(Btn) do
35        if Btn in Buttons then
36          Temp.Add(TypInfo.GetEnumName(TypeInfo(TMsgDlgBtn), Ord(Btn)));
37      Result := Format('[%s]', [Temp.Commatext]);
38    finally
39      Temp.Free;
40    end;
41  end;


			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC