Solved

TMainmenu at runtime

Posted on 1998-12-15
6
438 Views
Last Modified: 2010-04-04
Hey there here's my quesrtion,

I have created my own toolbar component that can create and remove buttons from a toolbar at runtime. That part works fine. The next step I need to produce is some sort of way to link the buttons produced to a procedure/function on the mainmenu ie a shortcut. I then will save this to an ini file for loading next time I come into the app. Is it possible to
actually capture the procedure at runtime(dynamically) and assign the procedure to the OnClick event of the Button on the ToolBar. A bugger of a question I know but there must some way of doing this without heading to Win API commands. I have thought of making my own TMainmenu with a few extra methods but will see if this can be done first.

Anyone got any ideas???

Regards Westy {:|
       
0
Comment
Question by:westy100697
  • 5
6 Comments
 
LVL 12

Accepted Solution

by:
rwilson032697 earned 150 total points
Comment Utility
You can do this using the RTTI information;

Assuming two components (Fred1 and Mary1) I can assign the onclick property from one to the other like this using the RTTI. This means that all you have to do is store the component and method names and you can assign it all using this technique.

var
 MaryPropInfo :  PPropInfo;
 FredPropInfo :  PPropInfo;

begin
  MaryPropInfo := GetPropInfo(Mary1.ClassInfo, 'OnClick');
  FredPropInfo := GetPropInfo(Fred1.ClassInfo, 'OnClick');
  SetMethodProp(Fred1, FredPropInfo, GetMethodProp(Mary1, MaryPropInfo));
end;

Cheers,

Raymond.

0
 
LVL 12

Expert Comment

by:rwilson032697
Comment Utility
Of course, you say, this is the same as this:

Fred1.OnClick := Mary1.Onclick;  //!

However, if you do not know the method name in advance then its quite useful!

eg: Procedure CopyNamedEvent(Comp1, Comp2 : TComponent; Event : String);

var
     PropInfo1 :  PPropInfo;
     PropInfo2 :  PPropInfo;

    begin
      PropInfo1 := GetPropInfo(comp1.ClassInfo, Event);
      PropInfo2:= GetPropInfo(comp2.ClassInfo, Event);
      SetMethodProp(comp2, PropInfo2, GetMethodProp(Comp1, PropInfo1));
    end;

Cheers,

Raymond.
0
 
LVL 12

Expert Comment

by:rwilson032697
Comment Utility
The TypInfo (and dsgnintf) units can make fascinating reading if you are interested in how to copy and manipulate properties in a generic fashion...

Cheers,

Raymond.
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 12

Expert Comment

by:rwilson032697
Comment Utility
Actually, you should also look at the FindComponent class method and the MethodAddress function - these together with the bits and bobs outlined above should do the job...

If you need any more pointers just yell :-)

Cheers,

Raymond.
0
 

Author Comment

by:westy100697
Comment Utility
rwilson,
           Gee this is becoming a habit you answering my questions...good habit though. I had a read through what you put here and was not quite clear on what you gave me. I then proceeded to put it into action and you little ripper it works. How did you happen to come across this? Both those units you told me to have a look at are very, very good reading. Handy to know eh. I was about to ask you a little extra question but I answered that myself whilst typing so I will give you the points and a big pat on the back. Thanks a lot
rwilson. Excellent Answer.

WESTY :)
0
 
LVL 12

Expert Comment

by:rwilson032697
Comment Utility
Westy,

I'm glad to help! I got into this stuff when D2 was new working with probably the first form designer external to the Delphi one that was developed (fedit2). Its very interesting stuff and has pretty awesome applications when you think about what you can do with it.

Cheers,

Raymond.
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

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…
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…
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…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

771 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

10 Experts available now in Live!

Get 1:1 Help Now