[Solved] Limit component property values to a subset of the standard enum'd list lazarus / 31-LCL ---------------------------------------------------------------------- jdlinke · 2014-07-15 04:31 This is probably a very simple question, but I can't seem to figure it out. I'm trying to write a new component based upon TCustomMemo, but I want to limit the enumeration of certain properties to only selected values. Specifically, in the Object Inspector, I want to be able to set: property ScrollBars ONLY to ssNone, ssHorizontal, or ssAutoHorizontal Is there a way to accomplish this? Do I need to somehow modify the ScrollBar property editor? Thanks for any assistance you guys can provide. ---------------------------------------------------------------------- Mike.Cornflake · 2014-07-15 07:12 I've played with trying to create to subsets before.  I don't think you can do it, and it's nothing to do with the IDE Inspector. I'd like to acheive something like the following, which is what I think you're after as well... Code: [Select]Type     TOption = (oOne, oTwo, oThree, oFour, oFive);     TOddOptions = Set of TOption = (oOne, oThree, oFive); I'm not entirely convinced that Pascal supports this... I actually needed this functionality for the patch in here... http://bugs.freepascal.org/view.php?id=26404 I wanted to create a subset of Process options.  Instead I ended up having to create my own Set, and manually map my set in code. Code: [Select]  TRunOption = (roStderrToOutPut, roNoConsole, roNewConsole); ...     If roStderrToOutPut in runoptions then       p.Options := p.Options + [poStderrToOutPut];     If roNoConsole in runoptions then       p.Options := p.Options + [poNoConsole];     If roNewConsole in runoptions then       p.Options := p.Options + [poNewConsole];You'll note I'm manually mapping the roXXX options (which are the subset) to their poXXX equivalents... I think you'll have to do the same...  (Be *very* happy to be told otherwise though) ---------------------------------------------------------------------- howardpc · 2014-07-15 08:02 The difficulty arises from the current design of TCustomMemo, not from any inherent inability of Object Pascal to do what you want. You would like to be able to override the TCustomMemo.SetScrollBars method to restrict the allowed options to a subset of TScrollStyle (and write a property editor which overrides the display of scrollbar options in the OI to show only the restricted subset). Unfortunately this cannot be done, since SetScrollBars is not declared as virtual; so it cannot be overridden. The only option I can see is to create an entirely new component, unrelated to TCustomMemo. It would have to be differently named, but have identical code (copied verbatim) except you would rewrite SetScrollBars to do what you wanted, (or make it virtual and then override it to do what you wanted). ---------------------------------------------------------------------- marcov · 2014-07-15 08:54 Afaik only by creating a custom property editor. ---------------------------------------------------------------------- JuhaManninen · 2014-07-15 09:19 Quote from: howardpc on July 15, 2014, 10:02:54 amThe only option I can see is to create an entirely new component, unrelated to TCustomMemo. It would have to be differently named, but have identical code (copied verbatim) except you would rewrite SetScrollBars to do what you wanted, (or make it virtual and then override it to do what you wanted). Hey, the situation is not so desperate. See: Code: [Select]  TjdlinkeMemo = class(TCustomMemo)   private     function GetScrollBars: TScrollStyle;     procedure SetScrollBars(const Value: TScrollStyle);   published     property Align;     ... all published properties from TMemo except for ScrollBars ...     property WordWrap;     // and then the new ScrollBars     property ScrollBars: TScrollStyle read GetScrollBars write SetScrollBars default ssNone;   end; implementation function TjdlinkeMemo.GetScrollBars: TScrollStyle; begin   Result := inherited ScrollBars; end; procedure TjdlinkeMemo.SetScrollBars(const Value: TScrollStyle); begin   if Value in [ssHorizontal, ssAutoHorizontal] then     inherited ScrollBars := Value   else     inherited ScrollBars := ssNone; end; It works but the object inspector would still show all values. It would only prevent the wrong value after user's selection. A proper solution requires a custom property editor as Marcov noted. Thus making SetScrollBars virtual would not help much. ---------------------------------------------------------------------- jdlinke · 2014-07-15 11:43 Thanks for the guidance everyone. I think I'll stick with JuhaManninen's recommendation. Not 100% ideal, but it meets my requirements, and I can add a comment to be displayed in the Object Inspector to alert an end-user to the limited set of options. Thanks again all! ---------------------------------------------------------------------- howardpc · 2014-07-15 18:43 Based on the code Juha provided a package is attached which includes a custom property editor to get the OI display to correspond with the restricted scrollbar options. The new component is placed on the Standard page (and has no custom icon), but this can of course be changed. ---------------------------------------------------------------------- jdlinke · 2014-07-15 22:40 howardpc: You're awesome! Exactly what I needed, and now I have a better idea of how to go about creating modified property editors. Thanks howardpc, and again, thanks to all of you who responded!