Include Forms in DLL

Abdulatif AL ABDOU
Abdulatif AL ABDOU used Ask the Experts™
on
I have a program in Delphi which i want to call it from C++QT;

So i want to make a (DLL) which contains a function in delphi to make an instance of the main form and launch the program...

I found many tutorial which all say that i have to do like this:

  frmDllForm :=TfrmDllForm.Create(nil);
  frmDllForm.Show;

** That does not work for the main window (Exception generated), but it does for a simple window from the same application...

The exception is: List Index is out-of-bounds...
Exception** Have you any idea which can help me please?

** Anybody know how to debug a dll in Embarcadero?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Sinisa VukSoftware architect
Top Expert 2012

Commented:
For first thing.... there is some reference to some resource which is not populated upon creating form probably. Does your form needs something in separate units? Better approach is to build dll form step by step - from simple form to more complex.

Second, debugging dll is easy. Best is to put dll project inside of main apps folder. Open dll project, put break-point somewhere,
then set under Run/Host app - put full path to main exe (which calls your dll). Then hit - (debug) run.

Author

Commented:
Hello Sinisa Vuk, thank you for your answer, it was helpful;

I found the source of the problem (By Installing madExcept ), indeed my delphi program use devexpress components; in the ribbon component, the skins are not charged; when the program try to use the first skin, it will search for it in a list which is empty!

I know now the source of the problem but i did not find yes how to solve it.

Author

Commented:
Now I think that the problem comes from la dll (gdiplus); there is a line in the code for exit the charging of the Skins when the program does not find the dll (GdiPlus)... My delphi program on windows 7... my c++ program on window 10
OWASP: Threats Fundamentals

Learn the top ten threats that are present in modern web-application development and how to protect your business from them.

Sinisa VukSoftware architect
Top Expert 2012

Commented:
Look for my comment for gdiplus on your another question thread.
Geert GOracle dba
Top Expert 2009

Commented:
another instance of the main form ????
created in a dll ?

the order is, launch the program and load the dll's
not the other way round

a main form holds a message queue and loads of other stuff which other forms don't
having 2 main forms in an app doesn't really work well

Author

Commented:
Geert G: No; It is not another instance of the main form. I will make a short story :)

I have a program in delphi; i want to make it a part of a c++ program; so the idea is to encapsulate the delphi program in a DLL and call it from the c++ program. So in the DLL; I made a function which will make an instance of the main program Delphi and show it; when the program try to create the main delphi form; all the  associated components will be created; for creating a specific component (TdxRibbon), we need the skins and by default we will use the first skin; but the list of skins is empty because (I think) the program can not load the GdiPlus.dll (May be because it is used in another program or may be because it does not find it at all ).
I expect that if you call CoInitialize this may go away.  If that doesn't solve it, It sounds like the skins are probably loaded in a units initialization section, and these do not all get called if not loaded correctly.  See this thread; https://stackoverflow.com/questions/4618650/delphi-unit-initialization-not-always-called

Are you accessing the DLL using static or dynamic loading.   This article explains the difference https://www.thoughtco.com/static-vs-dynamic-1058452

Reading the first linked article above, it sounds like if the DLL is loaded statically, and the initialization sections apparently do not get called unless the unit is explicitly in the projects uses clause.  i.e.  If a unit is in a another units uses clause, this may occur.  

This is not something I have ran into myself, but if I did, I would use loadlibrary to dynamically load your DLL.   This should resolve your issue.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial