Solved

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

Posted on 2007-04-08
6
183 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
  • 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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
LVL 28

Accepted Solution

by:
TName earned 500 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
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 demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

776 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