Componentes.Internos.PluginSDK/Source/uModuleMenu.pas
2007-05-29 16:46:50 +00:00

91 lines
2.0 KiB
ObjectPascal

unit uModuleMenu;
interface
uses
Menus;
type
{ IModuleMenu }
IModuleMenu = interface(IInterface)
['{8C844424-13F3-44D6-8B50-F723F964E816}']
function GetName: string;
procedure SetName(const Value: string);
property Name: string read GetName write SetName;
function GetItems(Index: Integer): TMenuItem;
property Items[Index: Integer]: TMenuItem read GetItems;
function GetItemsCount: Integer;
property ItemsCount: Integer read GetItemsCount;
function AddItem: TMenuItem;
end;
{ TModuleMenu }
TModuleMenu = class(TInterfacedObject, IModuleMenu)
private
FMenu: TMenu;
function GetName: string;
function GetItems(Index: Integer): TMenuItem;
function GetItemsCount: Integer;
procedure SetName(const Value: string);
public
constructor Create(const AMenuCaption: String);
destructor Destroy; override;
function AddItem: TMenuItem;
property Name: string read GetName write SetName;
property Items[Index: Integer]: TMenuItem read GetItems;
property ItemsCount: Integer read GetItemsCount;
end;
implementation
uses
SysUtils;
constructor TModuleMenu.Create(const AMenuCaption: String);
begin
FMenu := TMenu.Create(nil);
if AMenuCaption <> '' then
FMenu.Items.Caption := AMenuCaption;
inherited Create;
end;
destructor TModuleMenu.Destroy;
begin
FMenu.Free;
inherited;
end;
function TModuleMenu.AddItem: TMenuItem;
begin
Result := TMenuItem.Create(FMenu);
FMenu.Items.Add(Result);
end;
function TModuleMenu.GetName: string;
begin
Result := FMenu.Items.Caption;
end;
function TModuleMenu.GetItems(Index: Integer): TMenuItem;
begin
Result := FMenu.Items.Items[Index];
end;
function TModuleMenu.GetItemsCount: Integer;
begin
Result := FMenu.Items.Count;
end;
procedure TModuleMenu.SetName(const Value: string);
begin
if FMenu.Items.Caption <> Value then
FMenu.Items.Caption := Value;
end;
end.