Link to home
Start Free TrialLog in
Avatar of Peter Kiers
Peter KiersFlag for Netherlands

asked on

a procedure in a component calls a main-menu-item on the main form

Dear experts,

Sorry, to bother you again.

I have put this procedure in my component:

1.  procedure TMyDrawingPanel.CursorFlashTimer_OnTImer(sender: TObject);
2.  begin
3.  CursorFlashTimer.Enabled := False;
4.   try
5.  CursorVisible := not CursorVisible;
6.  finally
7. //   if (not CursorVisible) or (miFlashCursor.Checked) then CursorFlashTimer.Enabled := True;
8.   end;
9. end;

I get an error at line 7.

Because line 7 referse to a main-menu-item called miFlashCursor on the main form.

Is there a way to do this, that a procedure in a component calls a main-menu-item
that is on the main form.

Peter
Avatar of Eddie Shipman
Eddie Shipman
Flag of United States of America image

You will not always be able to be sure that that menu item even exists or even
named the same. The only thinkg you can do is to have the component store the
menu item that is being used to do this in another property and use that to "point"
to it.
Avatar of Peter Kiers

ASKER

Yes the menu-item will always exist and always named the same.

Because I use my component only in my application
If that is the case then you need to typecast the control's PARENT and then
access the menu item from there:

    if (not CursorVisible) or (TMyForm(Self.Parent).miFlashCursor.Checked) then
      CursorFlashTimer.Enabled := True;

Change TMyForm to the formthat your control is on.
ASKER CERTIFIED SOLUTION
Avatar of Eddie Shipman
Eddie Shipman
Flag of United States of America image

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
Your the best, thank you.

Peter Kiers