A MainMenu1-hez most nem adtam hozzá menuitem-et a Designer-ben.
Dinamikusan kellene hozzáadni (ahogy te is írtad), de ebben is futási hiba van. A Teljes főform kódja (Form1 , unit1.pas):
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, Menus;
type
{ TMyMenuItem }
TMyMenuItem = class(TMenuItem)
procedure SetLevel( level: integer );
function GetLevel(): integer;
private
{ private declarations }
public
{ public declarations }
// published
property
level: integer read GetLevel write SetLevel;
end;
{ TForm1 }
TForm1 = class(TForm)
MainMenu1: TMainMenu;
MenuItem1: TMyMenuItem;
procedure FormCreate(Sender: TObject);
procedure FormShow(Sender: TObject);
private
{ private declarations }
public
{ public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.lfm}
{ TMyMenuItem }
// set level
procedure TMyMenuItem.SetLevel( level: integer );
begin
self.level:=level;
end;
// get level
function TMyMenuItem.GetLevel(): integer;
begin
Result:=self.level;
end;
{ TForm1 }
// onshow
procedure TForm1.FormShow(Sender: TObject);
begin
MenuItem1.SetLevel( 1 );
ShowMessage( 'Level: ' + IntToStr( MenuItem1.GetLevel ) );
MenuItem1.SetLevel( 12 );
ShowMessage( 'Level: ' + IntToStr( MenuItem1.GetLevel ) );
end;
// oncreate
procedure TForm1.FormCreate(Sender: TObject);
begin
MenuItem1:=TMyMenuItem.Create( MainMenu1 );
end;
end.
Induláskor azonnal "Class TMenuItem not found.".
Valami még nem jó.