Recent

Author Topic: Lazarus and DLL Files  (Read 13820 times)

vazili

  • Newbie
  • Posts: 3
Lazarus and DLL Files
« on: February 11, 2014, 09:41:11 am »
Hi,

I am new here and I have a problem with DLL files. If I have in the DLL file a Form and I want to call it up then I get a message.
Projekt project1 hat Exception-Klasse "External: SIGSEGV" ausgelöst.
But only if I call the Form up. If I make only a procedure then I can gave me a string back and it works fine.

Does anyone can help me?
Thaks for your help!

Vazili

Windows 7 64 bit and Lazarus v 1.0.12.

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11383
  • FPC developer.
Re: Lazarus and DLL Files
« Reply #1 on: February 11, 2014, 12:01:10 pm »
The problem is that you have two copies of the LCL. One in the main program, one in the DLL.

There is afaik no general magic switch atm to make this work. A start would be to set the DLL's application object to the main programs.

A more long term solution is packages, like in Delphi: http://wiki.freepascal.org/packages

Mike.Cornflake

  • Hero Member
  • *****
  • Posts: 1260
Re: Lazarus and DLL Files
« Reply #2 on: February 11, 2014, 02:20:08 pm »
Interesting, there's another DLL thread going on at the moment.  For a working sample of a form being called from a DLL, see this thread:
http://forum.lazarus.freepascal.org/index.php/topic,22766.msg140950.html#msg140950

Sure, there's issues over there - PopupMenu isn't working, but it seems to me Talker has got the rest of your issue sorted :-)
Lazarus Trunk/FPC Trunk on Windows [7, 10]
  Have you tried searching this forum or the wiki?:   http://wiki.lazarus.freepascal.org/Alternative_Main_Page
  BOOKS! (Free and otherwise): http://wiki.lazarus.freepascal.org/Pascal_and_Lazarus_Books_and_Magazines

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11383
  • FPC developer.
Re: Lazarus and DLL Files
« Reply #3 on: February 11, 2014, 03:24:27 pm »
Interesting, there's another DLL thread going on at the moment.  For a working sample of a form being called from a DLL, see this thread:
http://forum.lazarus.freepascal.org/index.php/topic,22766.msg140950.html#msg140950

Quote
Sure, there's issues over there - PopupMenu isn't working, but it seems to me Talker has got the rest of your issue sorted :-)

I describe the general problem. He describes one specific hack for one very small aspect of the problem. The LCL programs can't be divided over dlls and mainprogram without some serious hacking. (that might be widget specific too)

Just look at the bugreport that he references, and then at the related bugreports.
They are all  closed as not fixable and reference to the packages wiki for more explanation.

That is for a reason :-)

Mike.Cornflake

  • Hero Member
  • *****
  • Posts: 1260
Re: Lazarus and DLL Files
« Reply #4 on: February 11, 2014, 04:53:42 pm »
Quote
Just look at the bugreport that he references, and then at the related bugreports.
They are all  closed as not fixable and reference to the packages wiki for more explanation.

That is for a reason :-)
Hmm.  It was me that dug out and referenced the bug report.  I didn't see any mention that the bug was unfixable, instead I saw reasonable caution and a patch that appears to work.   Of the three related bugs, two of them were closed out as resolved, and only one left open.

I've now read through the related bugs (and a few more), and on one that was left open indeed on one of them Vincent raises the same concerns you do here.   And phew, reading http://wiki.lazarus.freepascal.org/packages makes my head hurt.

So, how to proceed?  I don't have expectations that Lazarus is perfect, and I'm impressed that the LCL can be accessed at all through DLLs.  I'm guessing that you're just raising the concerns that people who proceed down this path should simply be aware that they may encounter unfixable problems. 

UPDATE:  Been thinking this one over...  Or are you saying that the people should not attempt this at all?
« Last Edit: February 11, 2014, 05:17:12 pm by Mike.Cornflake »
Lazarus Trunk/FPC Trunk on Windows [7, 10]
  Have you tried searching this forum or the wiki?:   http://wiki.lazarus.freepascal.org/Alternative_Main_Page
  BOOKS! (Free and otherwise): http://wiki.lazarus.freepascal.org/Pascal_and_Lazarus_Books_and_Magazines

vazili

  • Newbie
  • Posts: 3
Re: Lazarus and DLL Files
« Reply #5 on: February 11, 2014, 05:51:49 pm »
Hi again,

thank you for your fast replay!!!!
And that you try to help me!
But I am just new with the programming also and I didn't  understand what you want to say marcov.


The problem is that you have two copies of the LCL. One in the main program, one in the DLL.
I understand that I have called up two times the LCL.

There is afaik (what is that?) no general magic switch atm (what is that?) to make this work.
A start would be to set the DLL's application object to the main programs.

The last sentense mean to compile it again and it works again.

A more long term solution is packages, like in Delphi: http://wiki.freepascal.org/packages
I looked to this link but I understnad just nothing....  :o

Please help me!

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11383
  • FPC developer.
Re: Lazarus and DLL Files
« Reply #6 on: February 12, 2014, 11:24:35 am »

Of the three related bugs, two of them were closed out as resolved, and only one left open

(Note that unfixable reports can be set to resolved too)

UPDATE:  Been thinking this one over...  Or are you saying that the people should not attempt this at all?

In general: yes, IMHO you shouldn't attempt this at all.

There are exceptions though, knowledgeable people, or people only wanting
only a few simple use cases might get away with it by careful programming and a hack here and there, but there are no guarantees.

The most important bit is however that people understand what they are getting themselves into.

Mike.Cornflake

  • Hero Member
  • *****
  • Posts: 1260
Re: Lazarus and DLL Files
« Reply #7 on: February 12, 2014, 03:54:10 pm »
The most important bit is however that people understand what they are getting themselves into.

Understood.  Many thanks for the clarification.
Lazarus Trunk/FPC Trunk on Windows [7, 10]
  Have you tried searching this forum or the wiki?:   http://wiki.lazarus.freepascal.org/Alternative_Main_Page
  BOOKS! (Free and otherwise): http://wiki.lazarus.freepascal.org/Pascal_and_Lazarus_Books_and_Magazines

vazili

  • Newbie
  • Posts: 3
Re: Lazarus and DLL Files
« Reply #8 on: February 13, 2014, 09:10:11 pm »
I want to understand it but I couldn't.
Could you please help me marcov or Mike.Cornflake?
I want just to call up a Form out of a DLL in my program.

What I have to done?

Thank's for your help!

Michl

  • Full Member
  • ***
  • Posts: 226
Re: Lazarus and DLL Files
« Reply #9 on: February 13, 2014, 09:41:24 pm »
Did you tried Mike.Cornflake linked example. It works, code looks good and give you a idea, how you can solve your job http://forum.lazarus.freepascal.org/index.php/topic,22766.msg140950.html#msg140950
Code: [Select]
type
  TLiveSelection = (lsMoney, lsChilds, lsTime);
  TLive = Array[0..1] of TLiveSelection;

 

TinyPortal © 2005-2018