?
Solved

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

Posted on 2007-04-08
6
Medium Priority
?
187 Views
Last Modified: 2010-04-05
Dear Experts,

Hi, i have asked this question before, and without testing the code that I have
received I have awarded the points. And after givin the point I found out that
the code didn't work. My fault.

This was my previous question:
http://www.experts-exchange.com/Programming/Languages/Pascal/Delphi/Q_22494756.html

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, or any other form?

Who knows the answer and is willing to help me?

Greetings,

Peter Kiers
0
Comment
Question by:peterkiers
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 
LVL 28

Expert Comment

by:TName
ID: 18873419
Hi, I'm afraid I'll have to give you a very similar answer to the one Eddie did in the mentioned PAQ.
Correcty applied, his first answer should work  IF the parent of your component's instance is the main form.
If not, please tell us how the component is placed on the form...

BTW, things would be much easier if you'd always mention what exactly doesn't work, e.g. quote the exact error message... It is very frustrating to give an answer (that you're quite confident should work) and then only hear: It doesn't work.

Let's take this example: If for instance you do what Eddie advised you to do, and you try
(TMainForm(Self.Parent).miFlashCursor.Checked)  // let's presume your main form is of the type TMainForm...
and you get an error message saying "Undeclared identifier TMainForm", then we know that the main form's unit isn't included in the component's uses clause.

So, did you try something like this (you have to typecast Self.Parent to whatever your main forms CLASS is!):

 //if  for instance your main form is called Form1 then
 if  {...}  (TForm1(Self.Parent).miFlashCursor.Checked) then CursorFlashTimer.Enabled := True;


 //if  for instance your main form's is called MainForm then
 if  {...}  (TMainForm(Self.Parent).miFlashCursor.Checked) then CursorFlashTimer.Enabled := True;

And make sure your main form is included in your component's uses clause. To avoid a circular reference you have to include it in the implementation section:

// In your component's unit !!
implementation
uses Unit1;    // or whatever your main form's unit name is!

If on the other hand the main form is NOT the component's parent (e.g. if the component is placed on a panel or scrollbox or the like), you can try to hardcode the form's name, just to see if it works:

   Form1.miFlashCursor.Checked   // or MainForm.miFlashCursor.Checked


If it still doesn't work, please say so and I will post a small working example application...
 
0
 
LVL 28

Expert Comment

by:TName
ID: 18873468
BTW, if for instance the component is placed on a panel which is placed on the form, then you could also try .Parent.Parent:
("climbing up" the parent hierarchy...)

(TForm1(Self.Parent.Parent).miFlashCursor.Checked)
0
 
LVL 1

Author Comment

by:peterkiers
ID: 18873471
I had allready done it, but I get an EAccessViolation at this line:

    if (not CursorVisible) or (TMainForm(Self.Parent).miFlashCursor.Checked) then

I can't find out what I am doing wrong?

Peter
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 28

Accepted Solution

by:
TName earned 2000 total points
ID: 18873485
Is the form the component's parent?

Try  

(MainForm.miFlashCursor.Checked)

to see if it works...
0
 
LVL 1

Author Comment

by:peterkiers
ID: 18873489
This was the problem:

(TForm1(Self.Parent.Parent).miFlashCursor.Checked)

Now it works.

Thank you very much for helping me.

Greetings,

Peter Kiers
0
 
LVL 28

Expert Comment

by:TName
ID: 18873496
You're welcome, thanks!
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Suggested Courses
Course of the Month11 days, 21 hours left to enroll

752 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