Does anyone have any suggestions for representing an enumerated Set in the GUI? Thanks, -- Warm Regards, Lee
![]() |
0 |
![]() |
Lee Jenkins wrote: > Does anyone have any suggestions for representing an enumerated Set > in the GUI? I usually use a TChecklistbox for that. One item per element of the enumeration, checked items included in the set on display. -- Peter Below (TeamB) Don't be a vampire (http://slash7.com/pages/vampires), use the newsgroup archives : http://www.tamaracka.com/search.htm http://groups.google.com
![]() |
0 |
![]() |
Peter Below wrote: > Lee Jenkins wrote: > >> Does anyone have any suggestions for representing an enumerated Set >> in the GUI? > > I usually use a TChecklistbox for that. One item per element of the > enumeration, checked items included in the set on display. > Interesting. Never had an occasion to use the TCheckListBox. Peter, how do you enumerate the set, do you mind? Thanks again, Warm Regards, Lee
![]() |
0 |
![]() |
Lee Jenkins wrote: > Peter Below wrote: >> Lee Jenkins wrote: >> >>> Does anyone have any suggestions for representing an enumerated Set >>> in the GUI? >> I usually use a TChecklistbox for that. One item per element of the >> enumeration, checked items included in the set on display. >> > > Interesting. Never had an occasion to use the TCheckListBox. Peter, how do you > enumerate the set, do you mind? > Let me explain. I want to create a mediator for it so I'll know nothing about the the set as far as its range, etc. -- Warm Regards, Lee
![]() |
0 |
![]() |
Lee Jenkins wrote: > Lee Jenkins wrote: >> Peter Below wrote: >>> Lee Jenkins wrote: >>> >>>> Does anyone have any suggestions for representing an enumerated Set >>>> in the GUI? >>> I usually use a TChecklistbox for that. One item per element of the >>> enumeration, checked items included in the set on display. >>> >> Interesting. Never had an occasion to use the TCheckListBox. Peter, how do you >> enumerate the set, do you mind? >> > > Let me explain. I want to create a mediator for it so I'll know nothing about > the the set as far as its range, etc. > Only needed it one place in the application so I hard coded a specialized mediator for it. It' not every day when I have to represent a set in the GUI in this particular way so I'll delve into how to do this when I have more time... To the the FutureFollowUps folder... So solved (sort of) for now. -- Warm Regards, Lee
![]() |
0 |
![]() |
Lee Jenkins wrote: > Interesting. Never had an occasion to use the TCheckListBox. Peter, > how do you enumerate the set, do you mind? Here's an example of enumerating a set. Modify to suit <g> uses TypInfo; function SetToString(ATypeInfo: PTypeInfo; Value: Integer; Brackets: Boolean): string; var S: TIntegerSet; BaseTypeInfo: PTypeInfo; I: Integer; begin Result := ''; Integer(S) := Value; BaseTypeInfo := GetTypeData(ATypeInfo)^.CompType^; for I := 0 to SizeOf(Integer) * 8 - 1 do if I in S then begin if Result <> '' then Result := Result + ','; Result := Result + GetEnumName(BaseTypeInfo, I); end; if Brackets then Result := '[' + Result + ']'; end; eg: SetToString(TypeInfo(TBorderIcon), AForm.BorderIcons, True); -- Dave Nottage [TeamB]
![]() |
0 |
![]() |
Dave, | Here's an example of enumerating a set. Modify to suit <g> What if one has more than 32 elements in a set? <g> -- Q 08/18/2008 16:01:15 XanaNews Version 1.18.1.52 [Everyone's & Q's Mods]
![]() |
0 |
![]() |
> {quote:title=Quentin Correll wrote:}{quote} > Dave, > > | Here's an example of enumerating a set. Modify to suit <g> > > What if one has more than 32 elements in a set? <g> > > -- > Q > > 08/18/2008 16:01:15 > > XanaNews Version 1.18.1.52 [Everyone's & Q's Mods] This is a more generic approach, I think. Again, adapt as needed: type TStatusOption = (soQuoteOnly{0}, soUnknown{1}, soOutstanding{2}, soDelivered{3}, soReceived{4}, soCompleted{5}, soCollected{6}, soAll{high(TStatusOption)}); type TStatusOptions = set of TStatusOption; function StatusList : tStringList; // return a stringlist containing state names function StatusName(aState:tStatusOption):string; // return the name of a specific status option function StatusValue(aStateName: string): tStatusOption; // return the state value for a state name .... {*------------------------------------------------------------------------------ return a stringlist containing state names attaches the state value in the object reference caller is responsible for destruction of result ------------------------------------------------------------------------------*} function StatusList : tStringList; var soState : TStatusOption; begin result := tStringList.create; //<note> how do you escape the square brackets in this forum? // you need to change the angle brackets <> // to square pascal set brackets in the following line // the square brackets turn the line into a URL for soState in <low(tStatusOption)..high(tStatusOption)> do begin result.AddObject(StatusName(soState), tObject(soState)); end; end; {*------------------------------------------------------------------------------ return the name of a specific status option ------------------------------------------------------------------------------*} function StatusName(aState:tStatusOption):string; begin // get raw name result := GetEnumName(TypeInfo(tStatusOption), ord(aState)); // strip off the 'so' prefix result := copy(result,3,length(result)); end; {*------------------------------------------------------------------------------ return the state value for a state name ------------------------------------------------------------------------------*} function StatusValue(aStateName: string): tStatusOption; // var soState : TStatusOption; sDesired : string; sCandidate : string; begin result := soUnknown; sDesired := uppercase(aStateName); if (ansileftstr(sDesired,2) = 'SO') then begin sDesired := copy(sDesired,3,length(sDesired)); // strip off prefix end; // find the desired state name in the enumeration // note again <> => square brackets for soState in <low(tStatusOption)..high(tStatusOption)> do begin sCandidate := uppercase(StatusName(soState)); if sCandidate = sDesired then begin result := soState; break; end; end; end; ----------------------------------- Keith Edited by: Keith Latham on Aug 19, 2008 9:10 AM
![]() |
0 |
![]() |
Keith Latham wrote: > This is a more generic approach, I think. Again, adapt as needed: My idea of "generic" must be vastly different to yours. -- Dave Nottage [TeamB]
![]() |
0 |
![]() |
> {quote:title=Dave Nottage wrote:}{quote} > Keith Latham wrote: > > > This is a more generic approach, I think. Again, adapt as needed: > > My idea of "generic" must be vastly different to yours. > > -- > Dave Nottage [TeamB] Why vastly different? Quentin asked about more than 32 items. My method handles any number of elements and demonstrates two way access to element values and names, this is what I meant by more generic. However it does not work on assigned enums ( statevalue=47 ) because they do not have RTTI
![]() |
0 |
![]() |
Keith, | This is a more generic approach, I think. Again, adapt as needed: Thanks! I think I'll file that under "Things I may need someday." -- Q 08/18/2008 16:40:20 XanaNews Version 1.18.1.52 [Everyone's & Q's Mods]
![]() |
0 |
![]() |
Dave Nottage wrote: > Lee Jenkins wrote: > >> Interesting. Never had an occasion to use the TCheckListBox. Peter, >> how do you enumerate the set, do you mind? > > Here's an example of enumerating a set. Modify to suit <g> > > uses > TypInfo; > > function SetToString(ATypeInfo: PTypeInfo; Value: Integer; Brackets: > Boolean): string; > var > S: TIntegerSet; > BaseTypeInfo: PTypeInfo; > I: Integer; > begin > Result := ''; > Integer(S) := Value; > BaseTypeInfo := GetTypeData(ATypeInfo)^.CompType^; > for I := 0 to SizeOf(Integer) * 8 - 1 do > if I in S then > begin > if Result <> '' then > Result := Result + ','; > Result := Result + GetEnumName(BaseTypeInfo, I); > end; > if Brackets then > Result := '[' + Result + ']'; > end; > > eg: > > SetToString(TypeInfo(TBorderIcon), AForm.BorderIcons, True); > Thanks Dave, -- Warm Regards, Lee
![]() |
0 |
![]() |
Keith Latham wrote: >> {quote:title=Quentin Correll wrote:}{quote} >> Dave, >> >> | Here's an example of enumerating a set. Modify to suit <g> >> >> What if one has more than 32 elements in a set? <g> >> > > This is a more generic approach, I think. Again, adapt as needed: > > function StatusList : tStringList; > var soState : TStatusOption; > begin > result := tStringList.create; > > //<note> how do you escape the square brackets in this forum? > // you need to change the angle brackets <> > // to square pascal set brackets in the following line > // the square brackets turn the line into a URL > > for soState in <low(tStatusOption)..high(tStatusOption)> do begin > result.AddObject(StatusName(soState), tObject(soState)); > end; > end; > > {*------------------------------------------------------------------------------ > return the name of a specific status option > ------------------------------------------------------------------------------*} > function StatusName(aState:tStatusOption):string; > begin > // get raw name > result := GetEnumName(TypeInfo(tStatusOption), ord(aState)); > // strip off the 'so' prefix > result := copy(result,3,length(result)); > end; > > {*------------------------------------------------------------------------------ > return the state value for a state name > ------------------------------------------------------------------------------*} > function StatusValue(aStateName: string): tStatusOption; // > var soState : TStatusOption; > sDesired : string; > sCandidate : string; > begin > result := soUnknown; > sDesired := uppercase(aStateName); > if (ansileftstr(sDesired,2) = 'SO') then begin > sDesired := copy(sDesired,3,length(sDesired)); // strip off prefix > end; > // find the desired state name in the enumeration > > // note again <> => square brackets > > for soState in <low(tStatusOption)..high(tStatusOption)> do begin > sCandidate := uppercase(StatusName(soState)); > if sCandidate = sDesired then begin > result := soState; > break; > end; > end; > end; > > ----------------------------------- > Keith > Slick. Ready to apply to any TStrings property like the .Items property of the TCheckListBox that Peter suggested. -- Warm Regards, Lee
![]() |
0 |
![]() |
> {quote:title=Lee Jenkins wrote:}{quote} > > Slick. Ready to apply to any TStrings property like the .Items property of the > TCheckListBox that Peter suggested. > > -- > Warm Regards, > > Lee Thanks Notice however that my suite of routines is not "generic" in the sense that Dave Nottage would like. He passes the type info into his routine so its "generic" for any enumerated set. My suite of routines are specific to a particular set; the typeinfo is determined inside the method; so if you have several sets you need several suites. Seems to me a little thought could combine the two approaches to get the best of both worlds. I might think about it next time I need it. And yeah, that is the purpose of the stringlist output. I usually use the output in a combobox, but checkboxes and radiogroups are appropriate under various conditions.
![]() |
0 |
![]() |
From our component library: procedure TPsStateItemList.AddEnumValues(TypeInfo: PTypeInfo); var P: Integer; T: PTypeData; begin T := GetTypeData(GetTypeData(TypeInfo)^.BaseType^); for P := T^.MinValue to T^.MaxValue do AddState(GetEnumName(TypeInfo, P), P); end; Replace AddState with, for example, StringList.AddObject(GetEnumName(TypeInfo, P), TObject(P)) (Keith's version strips the first lowercase characters from the GetEnumName - which would be a good addition here, too) You can then get the enum value back from the list with TYourEnumType(StringList.Objects[StringList.ItemIndex]); Combine with bits of Dave's code to get it working with sets. BR, Jouni
![]() |
0 |
![]() |
Lee Jenkins wrote: > Lee Jenkins wrote: > > Peter Below wrote: > >> Lee Jenkins wrote: > > > > >>> Does anyone have any suggestions for representing an enumerated > Set >>> in the GUI? > >> I usually use a TChecklistbox for that. One item per element of the > >> enumeration, checked items included in the set on display. > > > > > > > Interesting. Never had an occasion to use the TCheckListBox. > > Peter, how do you enumerate the set, do you mind? > > > > Let me explain. I want to create a mediator for it so I'll know > nothing about the the set as far as its range, etc. The mediator needs to have available the typeinfo reference for the enumerated type (Typeinfo(TMyEnumType) gets you that as an opaque pointer). With that you can use routines from the TypInfo unit to figure out low and high bounds of the type (the matching ordinal values in fact), from that you can deduce the the size of a set of that type and get the string names for the enumeration members. If you don't want to display the enum member names as they appear in the source code the mediator would also need an array of display strings to use instead. You have to use the ordinal values of the enumerated type as index if you want this to be generic. -- Peter Below (TeamB) Don't be a vampire (http://slash7.com/pages/vampires), use the newsgroup archives : http://www.tamaracka.com/search.htm http://groups.google.com
![]() |
0 |
![]() |
Peter Below wrote: > Lee Jenkins wrote: > >> Lee Jenkins wrote: >>> Peter Below wrote: >>>> Lee Jenkins wrote: >>>> >>>>> Does anyone have any suggestions for representing an enumerated >> Set >>> in the GUI? >>>> I usually use a TChecklistbox for that. One item per element of the >>>> enumeration, checked items included in the set on display. >>>> >>> Interesting. Never had an occasion to use the TCheckListBox. >>> Peter, how do you enumerate the set, do you mind? >>> >> Let me explain. I want to create a mediator for it so I'll know >> nothing about the the set as far as its range, etc. > > The mediator needs to have available the typeinfo reference for the > enumerated type (Typeinfo(TMyEnumType) gets you that as an opaque > pointer). With that you can use routines from the TypInfo unit to > figure out low and high bounds of the type (the matching ordinal values > in fact), from that you can deduce the the size of a set of that type > and get the string names for the enumeration members. If you don't want > to display the enum member names as they appear in the source code the > mediator would also need an array of display strings to use instead. > You have to use the ordinal values of the enumerated type as index if > you want this to be generic. > Nice. Thank you. -- Warm Regards, Lee
![]() |
0 |
![]() |
Dave Nottage wrote: > > Here's an example of enumerating a set. Modify to suit <g> > > uses > TypInfo; > > function SetToString(ATypeInfo: PTypeInfo; Value: Integer; Brackets: > Boolean): string; > var > S: TIntegerSet; > BaseTypeInfo: PTypeInfo; > I: Integer; > begin > Result := ''; > Integer(S) := Value; > BaseTypeInfo := GetTypeData(ATypeInfo)^.CompType^; > for I := 0 to SizeOf(Integer) * 8 - 1 do > if I in S then > begin > if Result <> '' then > Result := Result + ','; > Result := Result + GetEnumName(BaseTypeInfo, I); > end; > if Brackets then > Result := '[' + Result + ']'; > end; > > eg: > > SetToString(TypeInfo(TBorderIcon), AForm.BorderIcons, True); Very interesting. Caused me to lookup rtti in delphi and found this article by brian long (about.com also has more about using rtti including a ref to this article). http://www.blong.com/Conferences/BorConUK98/DelphiRTTI/CB140.htm Thanks for bring this up. As I understand it, all the rtti is included in the exe whether you refer to it or not. I suspect that enumerated sets would not be included unless you used the GetEnumName on them. If anyone knows different, it would be nice to know.
![]() |
0 |
![]() |
> {quote:title=Joe Hicks wrote:}{quote} > Dave Nottage wrote: > > > > > Here's an example of enumerating a set. Modify to suit <g> > > > > uses > > TypInfo; > > > > function SetToString(ATypeInfo: PTypeInfo; Value: Integer; Brackets: > > Boolean): string; > > var > > S: TIntegerSet; > > BaseTypeInfo: PTypeInfo; > > I: Integer; > > begin > > Result := ''; > > Integer(S) := Value; > > BaseTypeInfo := GetTypeData(ATypeInfo)^.CompType^; > > for I := 0 to SizeOf(Integer) * 8 - 1 do > > if I in S then > > begin > > if Result <> '' then > > Result := Result + ','; > > Result := Result + GetEnumName(BaseTypeInfo, I); > > end; > > if Brackets then > > Result := '[' + Result + ']'; > > end; > > > > eg: > > > > SetToString(TypeInfo(TBorderIcon), AForm.BorderIcons, True); > > Very interesting. Caused me to lookup rtti in delphi and found this > article by brian long (about.com also has more about using rtti > including a ref to this article). > > http://www.blong.com/Conferences/BorConUK98/DelphiRTTI/CB140.htm > > Thanks for bring this up. As I understand it, all the rtti is included > in the exe whether you refer to it or not. I suspect that enumerated > sets would not be included unless you used the GetEnumName on them. If > anyone knows different, it would be nice to know. RTTI is available for enumerated sets UNLESS you explicitly assign the elements a value. so this has RTTI: type TStatusOption = (soQuoteOnly{0}, soUnknown{1}, soOutstanding{2}, soDelivered{3}, soReceived{4}, soCompleted{5}, soCollected{6}, soAll{high(TStatusOption)}); this doesn't: type TStatusOption = (soQuoteOnly=0, soUnknown=10, soOutstanding=20, soDelivered=30, soReceived=40, soCompleted=50, soCollected=60, soAll=999);
![]() |
0 |
![]() |