Solved

TMainmenu at runtime

Posted on 1998-12-15
6
439 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
ID: 1351208
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
ID: 1351209
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
ID: 1351210
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 12

Expert Comment

by:rwilson032697
ID: 1351211
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
ID: 1351212
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
ID: 1351213
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

863 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

23 Experts available now in Live!

Get 1:1 Help Now