Solved

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

Posted on 2007-04-08
6
181 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 28

Accepted Solution

by:
TName earned 500 total points
Comment Utility
Is the form the component's parent?

Try  

(MainForm.miFlashCursor.Checked)

to see if it works...
0
 
LVL 1

Author Comment

by:peterkiers
Comment Utility
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
Comment Utility
You're welcome, thanks!
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

743 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

18 Experts available now in Live!

Get 1:1 Help Now