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
Solved

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

Posted on 2007-04-08
6
184 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
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…

792 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