Re: component nested in component
- From: "Bruce Roberts" <dontsendtober@xxxxxxxxxxxxxxxxxxxx>
- Date: Mon, 31 Oct 2005 11:19:58 -0500
"Juergen" <juergenschlinker@xxxxxx> wrote in message
news:1130608218.694618.282980@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
> I have the following problem:
> I created my own button-component that I want to link with a popupmenu
> which I want to create dynamically in my button-component.
> When using the component in delphi the user should NOT be able to link
> the button component with it's own popupmenu but should only be able to
> edit the menu's items.
>
> That's what I've done to achieve this:
>
> private
> fPopupMenu : TMainMenu;
> published
> property Menu: TMainMenu read fPopupMenu;
>
> constructor TMyPopupButton.create(aOwner:TComponent);
> begin
> inherited create(aOwner);
> fPopupMenu := TMainMenu.create(self);
> end;
>
> Somehow that doesn't work as planned. Being placed on the form for the
> first time the component adds this to the DFM:
>
> object TMyPopupButton: TLtPopupButton
> [...]
> object TMainMenu
> end
> end
>
> But as soon as I do something like a cut'n'paste with my component an
> additional mainmenu is created on the mainform(!).
> I guess this is somehow connected to the fact that the constructor is
> NOT only called when the component is placed on the form but also when
> I do something like a cut'n'paste. Maybe I will have to check
> componentstate in the contructor and only create the mainmenu when it's
> in "creation"-mode?
> Or maybe there's another function that's called only once when the
> component is placed on the form?
You might be able to use ComponentState.
A component is placed on a form when its Parent property is set. I can't
recall offhand if one can override this assignment.
If you wan't to restrict a user to only use the popup menu you create the
safest way to do this is to not have the component available to the user
when designing, instead provide editors and methods of your main component
to compensate. Personally I don't think this is a very good idea. It would
make more sense and be simpler, IMO, to have your component insure that any
popup menu assigned to it contained the menu items that you require.
.
- Follow-Ups:
- Re: component nested in component
- From: Juergen
- Re: component nested in component
- References:
- component nested in component
- From: Juergen
- component nested in component
- Prev by Date: Re: Drag-and-drop from Windows Explorer?
- Next by Date: Re: Multiple modems: Threads required?
- Previous by thread: component nested in component
- Next by thread: Re: component nested in component
- Index(es):