[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

TMainmenu at runtime

Posted on 1998-12-15
6
Medium Priority
?
449 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

649 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