Delphi - How to register a custom form - delphi

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..."

Related

How to add a "unit only" item to "New" menu/object repository in Delphi

I've seen numerous examples of how to add a form wizard to the Delphi Object Repository (for instance, in the TeeChart source), but I want to add the equivalent of the "New Unit" but just with content that I generate. In other words, I can't figure out how to JUST create a unit without creating a form with it. I am currently trying to do this via OTA in Delphi XE via the IOTAModuleCreator, but it wants a form ancestor. Is there a different interface I should use, is there someplace I can just pass a nil to avoid the form, or is this not even something that can be done?
Per what Sir Rufo said, this indeed did exactly as I was looking for:
https://github.com/VSoftTechnologies/DUnitX/blob/f-d10-seattle/Expert/DUnitX.Expert.NewUnitWizard.pas

How To Subclass A Form in Delphi? Best Practices?

I've got a base form in Delphi 2007 that I'd like to reuse in another project, adding some other buttons and such.
I'm familiar with subclassing a non-GUI object, but it is possible to subclass a Form in the same fashion? Can you make changes to the subclass Form in design mode?
How do you go about doing this and what are some things to look out for?
As idursun said (he was a little quicker than me):
Add the base form to your new project.
Then choose "File\New\More..."
Form the "Delphi-Projects" branch select "Inheritable Elements", find your base form and click "OK".
(The actual names of the menu items may vary since I am using a german version of Delphi 2009)
You can then make changes to your new or your base form.
If I do so I make sure to have both forms open in the IDE since sometimes it seems Delphi doesn't get all the changes if I don't.
You should add your base form to your new project and in the new form window there should be an Inherit tab where you can select a base form for the new form.

Generate Code for Invisible ActiveX Object Event Handlers in 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.

Writing a DLL for Excel in Delphi

I'm using Turbo Delphi 2006.
The DLL will be called from within Excel as part of a VBA/DLL combination.
The first part of the problem is trying to find out how to pass to the DLL a reference to the current Excel session. Most other code I've seen was that it launched a separate instance of Excel apart from the one you're in.
I've seen some C++ code that creates an instance of IDispatch and then passes something in to a method of the IDispatch object, but not knowing much C++.
Any ideas?
What you describe is called writing a COM addin. You need to create an automation DLL and implement the IDTExtensibility2 interface. You will then receive the Excel Application interface as a parameter to the OnConnection method.
You will also need to register your DLL as an addin so Excel will automatically load it.
EDIT: Forgot to mention: You might want to take a look at Add-in Express. Their framework and components make getting started with the creation of Office addins ridiculuously easy. You definitely won't have to bother with the details of IDTExtensibility2. All that comes with a (well-justified) price tag, though.
Delphi comes with a set of ActiveX controls to give complete access to Excel and the other Office applications. They should be on the "Servers" tab of the Tool Palette.
If the aren't there, then select Components|Install Packages, and scroll down the list there until the very end, and select the right package.
In a default installation, they should be called:
Microsoft Office Sample Automation Server Wrapper Components
and there should be one for XP and Win2k. The XP ones will work for Vista.
Now that if if you want to automate Excel.
If you merely want to add functionality to Excel by using Delphi, I'd suggest using a COM object, as I suspect that Excel is very accepting of COM objects. Otherwise, you can create a straight DLL, and use that the same way that Excel uses any other DLL.
I do not know much about Office, but I guess you should use COM/ActiveX. Then you also get your IDispatch. See http://delphi.about.com/od/comoleactivex/OLE_COM_DCOM_Automation_ActiveX_Delphi_knowledge_base.htm

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