Forum > General
Newbie question about custom controls
(1/1)
sniperton:
Hi, I'm very green in OOP and FP :'(, so forgive me for my stupidity. Thanks ;)
I'm coding a custom component which is a sort of container (inherited from TScrewPanel) for various other stock components like TMemo, TList, TStaticText, etc. Most of the elements are static (I need them every time), but one of them should be dynamic (I want to be able to select it from code in run-time): this time a TMemo, that time a TList, depending on the type of data the user has to enter (free text / selection from list / etc). As I have to work with dozens of such controls, I create them as array elements, and therefore I need a single type.
So far I made this in a way that all the interchangeable control-elements were created upon each other in the constructor procedure and later when I created the actual instance I simply disabled and hid the superfluous ones. But I think it's not very elegant :(.
Could anyone please advise me how to make my customised control parameter-driven? Surely I have to define some published properties and methods, but a little bit help would be much appreciated. Thanks
mas steindorff:
look into "Frames". The code looks like it's a separate form but it lives on the form you load it on. they can be added dynamically and you can code the create() code to include/remove whatever you want.
Martin_fr:
If you write your own component, and you want to creat stuff based on properties...
You can override the procedure "Loaded", at that time all properties are set, and you can create your subcomponents.
BUT, if your component isn't loaded (e.g. if you drop it onto the form in the designer), then "Loaded" is never called... So nothing happens.
Hence you can in the constructor test for
if not(csLoading in AOwner.ComponentState) then
CreateDefaults
You can also use that test in the property setters. So during loading property setters can skip chnaging the component (since Loaded will take care), but if a property changes outside the loading, it can change the subcomponents as required.
It get's more complex, if you want the subcomponents to have published properties, that can be edited, and streamed.
SynEdit and SynGutter do that. SynGutter can have any amount and combinations of Gutterparts, which are all edit-able through the designer, and all streamed to the lfm file, and loaded at runtime.
sniperton:
Thanks a lot! :)
Navigation
[0] Message Index