Generate Code for Invisible ActiveX Object Event Handlers in Delphi - delphi

You know in Visual Studio you can use the "+=" syntax and a couple tabs to have it autogenerate the code for an event handler?
How do I accomplish the same thing in Delphi? I'm trying to create an event handler for an event in an invisible activex library that I've imported using the Import Component function.
I realize that with imported activex controls you can just click the object, browse the events tab for what the component provides and double click on the event to have it generate one for you.
These particular activex components are invisible so you can select them on the form. Can Delphi autogenerate the code? If not, can someone point me to some sample code?

In Delphi, even non-visual components are represented on the form as small boxes with an icon. Just select that component and you can get to the events from the object inspector.
If you didn't install it on the component pallet, then there is no autogeneration of the code for the event handler. The easiest way would be to go into the generated tlb.pas file and find the signature of the event you want, copy it, and make a compatible method for it. Then just point the event property to that new method.

Related

Adding declarations and definitions in the IDE for runtime components

I'm dealing with creating a number of components at runtime and setting their methods. Is there a way to add the declartion and definition stubs for a component without adding it to the form and clicking the corresponding event on the events tab?
I know I can add a component temporarily to create the stub, or sometimes the help files list the declaration. But there are a lot of features in the IDE that I have not found or used.
Replying to comments:
What I do currently is workable I just wondered if there was a shortcut I was missing. To reiterate as some did not understand; I am using component AwesomeComponent in my application. I only need to create instances of AwesomeComponent at runtime, so it is not on my form (or perhaps is non-visual). AmesomeComponent has an event DoSomething. That event has a number of parameters. In order to assign AmesomeComponent.OnDoSOmething at runtime, I need to code the event, but I don't have direct access to the procedure stub, I have to find it somewhere in documentation or create it on a dummy form to cut and paste it. I didn't know if there was an IDE feature that was smart enough to say "Ok, I recognize this name (AwesomeComponent.OnDoSOmething) as an event and create a stub for it. It must do essentially the same thing when double-clicking on the Events tab in the IDE.

How to easy replace MessageDlg with Vista dialog, Delphi 7

Delphi7 (cannot use latest). I want to replace (easy way, not making my form) MessageDlg calls with Vista style dialogs (must still work on old OS!). I need buttons Yes/No/YesToAll/NoToAll in this.
How to do it?
MessageBox isn't a way: I need all 4 buttons Yes/No/YesToAll/NoToAll in one form, or maybe checkbox instead of ToAll btns.
On Vista you use the native task dialog, TaskDialogIndirect. This has all the functionality you need. You'll need to translate the headers to Pascal, but if you don't fancy doing that yourself then you can use the JEDI header translations, for instance.
On XP and older there is no task dialog. There is no native system dialog with the functionality that you desire. Therefore you need to implement the dialog yourself. Create a Delphi TForm descendent. Add the necessary text, buttons, styling etc. Show it with ShowModal.
One of the issues with all this is that TaskDialogIndirect must be bound at runtime with GetProcAddress. In fact, use GetProcAddress to determine whether TaskDialogIndirect is available, and if not fall back to the XP code path.
If you don't want to build this yourself you can use one of the many extant libraries that offer such functionality. For instance: http://blog.synopse.info/post/2011/03/05/Open-Source-SynTaskDialog-unit-for-XP,Vista,Seven

Double click on a non-visual component [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How to invoke a property editor at design time
I'm creating a non-visual component, and I want the user to be able to double click on my component at design-time and have that open a design-time editor.
How can I do it?
Double-clicking a component at design time invokes a component editor. The default component editor is one that looks for event properties with certain names and creates a handler for what it finds. You can write your own component editor that does whatever you want.
Create a descendant of TComponentEditor (from the DesignEditors unit) and override the Edit method to handle double-clicks. You can also override the GetVerbCount, GetVerb, and ExecuteVerb methods to add context-menu items to your component. To get a reference to the component your editor is being asked to edit, check the Component property. Call Designer.Modified if your editor modifies the component.
Tell the IDE that your editor should be used with your component by calling RegisterComponentEditor (from DesignIntf) in your Register procedure.
You should put this code in a design-time package, separate from your component's code. Put your run-time package on the "requires" list of the design-time package. If you put everything in a single package, then consumers of your component won't be able to use run-time packages in their projects; they're not allowed to distribute the dependencies of your design-time package, which are only for use by the IDE.

Delphi - How to register a custom form

D6 Prof.
Because of Z-Order problem I created a new form. I want to register this custom form in Delphi, to I can use it as normal form, and to I can replace my forms with this - to avoid Z-Order problems.
But I don't know, how to do it.
I created the class, but how to register?
How to force Delphi to show it under "New..." menu?
Thanks for your help:
dd
If you added new properties or the like you have to call RegisterCustomModule() within a design-time package to register the form with Delphi. Use RegisterNoIcon to avoid registration in the component palette.
#durumdara, you can use the object repository from the delphi IDE.
check theses links
Working with the Delphi Object Repository
Using the Object Repository
Mastering Delphi 6 - Delphi Object Repository (Google books)
Right click the form and select "Add to repository..."

Best Way to Replace a Visual Component in Delphi

In a Delphi Form, I would like to replace one visual component with another. Example: I want to replace a Panel component with an ElPanel from a 3rd party package.
I would like all identical properties and events of the first component to be transferred to the new one, and all the components that belong to the first component (e.g. Toolbars, memos,status bars, etc.) to end up placed on the new component exactly where they were on the first one.
Is there a best/easiest way to do this other than adding the new component to the form and meticulously transferring every property, event and component to it one-by-one?
I do it as following:
Right click on the form and choose (View as Text).
Press Ctrl + F to search for the Component class name like TPanel and replace it with TElPanel
Switch back to back to the form (View as form)
In the interface section replace the TPanel with TElPanel.
if you have many components using GExperts will be more feasible solutions.
You can use GExperts or you can do it by hand.
To do it by hand, open the .dfm in notepad and replace all the class names. (Replace TPanel with TElPanel for example). When you've made all your changes, open the .pas file with Notepad, and do the same thing.
Make sure you add the required units to your uses clause.
Then open the form in the IDE and clean up any mismatched events or unknown property problems.
If I recall the excellent free GExperts plugin does this. Right click your form and select "Replace Components". http://www.gexperts.org
IMHO, the big drawback of the Replace component GExpert is that it changes the order of the components in the source code. That is not very VCS friendly. :-)
If you have other components inside a container doing this replacement with GExperts will cause some ugly exceptions and possibly unexpected behaviour in the IDE.
So, the best solution is to edit the .dfm file where you want (inside or outside the IDE) and replace manually the types of the components that you want to change. Maybe it will cause some exceptions too, but the IDE will managed them.
If you do it inside the IDE, after switching to design view if you save the .dfm inmediately the IDE will ask you to change the type of the variables related to the components you touched, liberating you to do it.
To convert between text and binary dfm formats, use the convert.exe tool in the Delphi bin\ directory. – Tim Knipe (Oct 28 at 4:15)
You can also use the context menu of the form designer - at least with BDS 2006. It's the last menu item ("Text-DFM" in a German IDE).
In my project I had to convert few doezens forms from one set of components to another.
I have created small perl script to convert components and its properties and do all neccesary mapings.
The script is quick&dirty solution but it is highly configurable. It scanns all dfm and pas files in project direcotory and convert dfm components definitions according to rules that you should provide in ObjectBeginFound, PropertyFound, ObjectEndFound procedures/events.
DFM files should be in text mode. Tested on Delphi 5 files. I don't know if it will be compatible with newer versions. Please send posts if you find it out.
USAGE:
perl.exe cxdfm.pl > logfile.txt
DOWNLOAD LINK
http://dl.dropbox.com/u/15887789/cxdfm.pl

Resources