Solved

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

Posted on 2007-04-05
5
163 Views
Last Modified: 2010-04-05
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
0
Comment
Question by:peterkiers
  • 3
  • 2
5 Comments
 
LVL 26

Expert Comment

by:EddieShipman
ID: 18859513
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.
0
 
LVL 1

Author Comment

by:peterkiers
ID: 18859617
Yes the menu-item will always exist and always named the same.

Because I use my component only in my application
0
 
LVL 26

Expert Comment

by:EddieShipman
ID: 18860225
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.
0
 
LVL 26

Accepted Solution

by:
EddieShipman earned 500 total points
ID: 18860228
Or just typecast it to TForm, that should work as well.
0
 
LVL 1

Author Comment

by:peterkiers
ID: 18860860
Your the best, thank you.

Peter Kiers
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now