Embed com obj in delphi's exe - delphi

I've made a dll in c# an made it com visible then used it in delphi. In order to do that i had to register the dll so that i could install that as a component in my delphi ide. (I registered the dll with the interop thing then in delphi went to install component > type library > selected my com dll and it created everything for use of it.)
The problem i'm facing now is that i want to use the exe on another machine without having to register the dll. Is it possible to compile the exe file with the registered com dlls?
I have a solution to this is to not use the com obj but just go with unmanaged dll and export all the methods i want but i would prefer embedding the dll/com into my exe and i can't seem to find a solution to this, i don't know if it's possible.

Use dynamic loading of CLR technique to load and use DLL. refer to this Hosting the .NET runtime in a Delphi Program you might get your answer.
In dynamic loading technique you need not register the DLL you just have to generate a TLB and interface for your DLL and through that use the DLL.

Related

Delphi XE3 App with ActiveX / COM objects

I'm a bit confused on something, being quite a while since I've used external controls. Basically, I'm writing a small test app with Delphi XE3 which uses an ActiveX control. A TLB file is generated as usual. I have tested on two machines (an Acer notebook and a Dell Latitude 10). When I test on my desktop Windows machine I get an error traceable to the OCX file. I was under the impression that the TLB.pas file was all that was needed to instantiate the control. Do I also need to install and register the OCX file ? Does COM component need to be distributed with its .DLL file ? TIA for your anticipated help.
Brian Corll
The type library only describes how to call the library. The .pas file generated from the type library also only describes how to call the library. That's all compile time. At run time when you actually call the library, you need the library to be registered and present.
So yes, you'll need to distribute and register the library.

Delphi: Can you have a component class definition in a DLL and load and create it at runtime?

Sorry if this is a silly question but it's not something I've had to do before.
Is it possible to create a component class, say, a descendent of TPanel or TDBGrid, in a DLL, and then load that DLL at runtime in another application, which then creates those controls and uses them like normal Delphi components?
If so can you give me any pointers as to where to look to start doing this?
That's what packages are for. They are a kind of DLL that is improved to play well with Delphi classes (including components).
Just remember that you'll need to distribute RTL[ver].bpl, VCL[ver].bpl and any other necessary Runtime Packages alongside your executable and DLL.
Ideally you should test your application on a VM or system which has never had Delphi/RAD Studio installed on it. This way, if your distribution is missing any required Package files, the Execption dialog will tell you what files you need to include.

Delphi DLL created from parented to calling application

I have an application that I make a call to a DLL function that creates and returns a form. I get a whole bunch of errors when I try to parent this new form to the main form in the application.
Is that a common error / problem or is there not an issue with parenting in this case.
And as far as I have learned a form created in a DLL call doesn't belong to the application. Is there a way to make the newly created form belong to the application.
Thank you,
Tim
compile your dll and exe with the same version of delphi compiler with the same runtime packages.
also in dll do not use any calling convension like stdcall or cdecl on your form-creating-function.
it will work like a charm.
Do not use VCL inside DLLs. You will encounter all kind of problems this way. If you absolutely need to have dynamic packages that create VCL components or other GUI parts, use BPLs for instance. Here is a short sumary of both:
BPL vs. DLL
Stack oveflow question
There are other aproaches. Now the main question is why do you create a form inside DLL and is that really needed?
Your dll and exe must be compiled in same version of RAD Studio and both must use runtime packages.

how to use system.xml.dll in delphi

I downloaded the system.xml.dll, then added it to my Delphi code as following:
uses system.xml;
etc...
When I try to compile the project, the following message appears:
file not found system.xml.dcu.
Can anyone guide me how to solve this problem?
Thanks.
The uses clause in Delphi refers to Delphi units, either compiled in a *.dcu file or a *.pas source file that the compiler will use to generate the corresponding *.dcu that is needed.
You cannot just reference the DLL itself.
To use your DLL, you would need at least a unit that would expose in a Pascal way the DLL interface or parts of it.
It can be the Pascal translation of a C header file or just declaring some external routines from the dll to load statically with your program...
What you probably need to reference to work with XML in Delphi are XMLIntf and maybe xmldom.
Have you looked at what the XML Data binding wizard or the XML Mapper Tool can do for you?
Note: I assumed you were working with Delphi Win32. And AFAIK system.xml.dll is part of the .NET world.
If you are using Delphi for .Net you need to add a reference to the system.xml.dll assembly to your project.
If you are using Delphi (Win32), then in order to be able to use .NET assemblies (DLLs), you have the option of using COM interfaces. Follow below steps:
Open the project you want to use it in.
Use Component menu.
Select "Import Type Library"
Select the DLL you want to use.
Follow the next steps as given by wizard.
This will generate a source file which is essentially a wrapper. You can call function of that wrapper as you need.
Please note that using above method will mean that .NET framework must be present on the computer running your application.

How to consume and re-expose a Win32 type library using Delphi Prism

I currently have a Win32 type library created in Delphi which I need to consume, implement and re-expose via .NET. What are the steps necessary to bring the TLB into Prism so the interface can be implemented?
the .NET 2.0 sdk tool TLBIMP can create an assembly from a TLB file. Something like:
tlbimp.exe mytlb.tlb /out:MyTLB.Import.dll /namespace:MyTLBImport
Make sure you use /publickey /keyfile or /keycontainer if you want to sign it later on.
After the import, just reference the dll and use it as a regular library.

Resources