I'm creating a MainMenuEx and have add property in MenuItem.
the property is called FormShowOptions.
the code of example is listed below:
Someone help me? Thank you very much
//----------------------------------------------------------------------
unit MyMainMenu;
interface
uses
SysUtils, Classes, Menus;
type
TFormShowOption = (fsoNormal, fsoMdi, fsoTabSheet);
TFormShowOptions = set of TFormShowOption;
TMyMenuItem = class(TMenuItem)
private
FFormShowOption: TFormShowOptions;
public
constructor Create(AOwner: TComponent); override;
procedure Add(Item: TMyMenuItem);
published
property FormShowOption: TFormShowOptions read FFormShowOption
write FFormShowOption;
end;
TMyMenu = class(TMenu)
private
FItems: TMyMenuItem;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
function CreateMenuItem: TMenuItem; override;
published
property Items: TMyMenuItem read FItems;
end;
TMyMainMenu = class(TMyMenu)
public
end;
implementation
{ TMyMenu }
constructor TMyMenu.Create(AOwner: TComponent);
begin
inherited;
FItems := TMyMenuItem.Create(Self);
end;
function TMyMenu.CreateMenuItem: TMenuItem;
begin
Result := TMyMenuItem.Create(Self);
end;
destructor TMyMenu.Destroy;
begin
FreeAndNil(FItems);
inherited;
end;
{ TMyMenuItem }
procedure TMyMenuItem.Add(Item: TMyMenuItem);
begin
Insert(GetCount, Item);
end;
constructor TMyMenuItem.Create(AOwner: TComponent);
begin
inherited;
FFormShowOption := [fsoNormal];
end;
//----------------------------------------------------------------------
--
> I´ll try explain my doubt.
Which is what exactly? All you have done so far is shown code but not
offered any description about it. What are you having problems with
exactly?
> Someone help me?
With what exactly?
Gambit
Hi Gambit,
Sorry has not explained right.
The problem is that I am not able to make the property created appears
in the new component. The component is that I am creating a TMainMenuEx.
I created a new class based on TMenuItem and call it a property
FormShowOption.
I want the property FormShowOption appears as a property of menu items.
Thank you.
--
> The problem is that I am not able to make the
> property created appears in the new component.
At design-time, the IDE's native menu designer will never create instances
of your custom TMyMenuItem class. That is why the property does not
appear - it does not actually exist in the items that are created! You are
overriding the TMenu.CreateMenuItem() method, which is fine for creating
menu items at run-time only. But at design-time, you would have to create
your own custom property editor and component editor in order to work with
TMyMenuItem instances.
Gambit
Thank you Gambit for your answer.
Your tip is very intersting and I'll try create the custom property
about your tip.
--