Link to home
Start Free TrialLog in
Avatar of Robert Gilland
Robert Gilland

asked on

Changing MenuItem at RunTime

How do you change a menuItem at Runtime.
I want to change the TMenuItem.Caption
component and refresh it. At RunTime.
Delphi seems to not allow this for some unknown
reason, I am using Delphi 1.0
Avatar of sleach
sleach

MenuItem.caption := 'NewCaption';

The above line works fine.  You CAN change the caption at runtime.  I just tested this to verify.

I suggest that you delete all temp files, and do a rebuild.  That will sometimes fix strange errors.
Avatar of Robert Gilland

ASKER

Edited text of question
I know I cant or else I wouldnt ask the
question. Maybe in Delphi 2 and above you can
but in Delphi 1 you cant.
sleach's suggestion seems to work fine for me in D1, I just created a new form with a TMainMenu, inserted the "File" menu template, then added a button to the form and put this as the OnClick event handler:

procedure TForm1.Button1Click(Sender: TObject);
begin
  New1.Caption := 'Newer' ;
end;

I run the program, the "File" menu shows normally with "New" as the first item, I click the button, now the first item has become "Newer" just as would be expected.  Is this not what you're referring to when you ask "How do you change a menuItem at Runtime?"  If it is and still isn't working, can you maybe post some source code so we can see more precisely how you're doing this?

SLP

ASKER CERTIFIED SOLUTION
Avatar of sleach
sleach

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I found the problem was that I was changing the caption
is tne OnClick event of the CLOSEBUTTON the event for
some reason did not actually occur, and I needed to change the
caption from within the unit I had the menu object in.