?
Solved

TMainmenu at runtime

Posted on 1998-12-15
6
Medium Priority
?
447 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
[X]
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
  • 5
6 Comments
 
LVL 12

Accepted Solution

by:
rwilson032697 earned 600 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

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…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses
Course of the Month9 days, 6 hours left to enroll

764 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