#1 2020-03-28 15:27:07

profh
Member
Registered: 2010-07-02
Posts: 159

How to put TDataModule in DLL with Lazarus

sorry for the topic not related to mORMot.
   
i have a server with mORMot using Delphi 10.3.3 under Windwos Server for years , thanks for ab and the great team.
i create another server also with mORMot using Lazaris 1.9.0. under CentOS 7, i put TDataModule in DLL, it raised exception,
"Failed to initialize component class "TDataModule1": No streaming method available."

here is the code:

library mydll;
{$mode objfpc}{$H+}

Uses
  fastMM4,
{$IFDEF UNIX}
  cthreads,
{$ENDIF}
   classes, Sysutils, lcl;

type
  TDataModule1 = class(TDataModule)
  private
  public
  end;

var
  sl:TStringlist;
  DataModule1: TDataModule1;

begin
  sl:=TStringlist.Create;
  try
    DataModule1:= TDataModule1.create(nil);       <--error 
  except on e:exception do begin
    sl.Add('2:' + e.Message);
    sl.SaveToFile('c:\sl.txt');
  end;
  end;
  DataModule1.free;
  sl.free;
end.
    

thanks for help.

Offline

#2 2020-03-28 17:12:48

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,182
Website

Re: How to put TDataModule in DLL with Lazarus

I suspect this is more a question for Lazarus/FPC than for mORMot.

To be honnest, I never used a TDataModule with FPC.
And mORMot is source-first, so you don't need TDataModule or any non-visual component.

Offline

#3 2020-03-28 22:05:38

profh
Member
Registered: 2010-07-02
Posts: 159

Re: How to put TDataModule in DLL with Lazarus

Yes, it is a tiresome question about Lazarus/FPC, and i manage to avoid using TDataModule.

Is there any alternative? I have some components and predefined functions/procedures in it.
thanks.

Offline

#4 2020-03-29 06:22:53

AOG
Member
Registered: 2014-02-24
Posts: 490

Re: How to put TDataModule in DLL with Lazarus

Try this, perhaps it helps.
TDataModule1.CreateNew(nil);

Offline

#5 2020-03-30 11:47:54

profh
Member
Registered: 2010-07-02
Posts: 159

Re: How to put TDataModule in DLL with Lazarus

@AOG, thanks, it seems to be ok. and i will practice it in my project and reply the message later.

Offline

#6 2020-04-06 08:46:05

profh
Member
Registered: 2010-07-02
Posts: 159

Re: How to put TDataModule in DLL with Lazarus

@ab, AOG:

yes, mORMot is source-first, so i gave up TDataModule and with fpcunit.TTestCase instead, it works.

many thanks!

Offline

#7 2020-04-08 08:46:09

profh
Member
Registered: 2010-07-02
Posts: 159

Re: How to put TDataModule in DLL with Lazarus

i got the linking error as follow when built the shared library, and it worked correct if i bulit the executive program directly.

  Verbose: linker: /usr/bin/ld: mORMot/static/x86_64-linux/sqlite3.o: relocation R_X86_64_32S against `.rodata' can not be used when making a shared object; recompile with -fPIC
  Verbose: linker: /usr/bin/ld: mORMot/static/x86_64-linux/ecclin64O2.o: relocation R_X86_64_32S against `.data' can not be used when making a shared object; recompile with -fPIC

thanks!

Offline

#8 2020-04-08 10:18:52

AOG
Member
Registered: 2014-02-24
Posts: 490

Re: How to put TDataModule in DLL with Lazarus

Put -Cg- in the project options.
Or try -Cg (without trailing -) also ... ;-)

Offline

#9 2020-04-08 13:16:49

profh
Member
Registered: 2010-07-02
Posts: 159

Re: How to put TDataModule in DLL with Lazarus

-Cg is the same as -fPIC,
i got the same error message with -Cg- in the custom options. sad

Offline

#10 2020-04-09 09:29:34

profh
Member
Registered: 2010-07-02
Posts: 159

Re: How to put TDataModule in DLL with Lazarus

is it possible that static/x86_64-linux/sqlite3.o and static/x86_64-linux/ecclin64O2.o should be compiled with -fPIC option?

thanks!

Offline

#11 2020-04-09 21:17:04

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,182
Website

Re: How to put TDataModule in DLL with Lazarus

You would have to compile it by yourself.

Offline

#12 2020-04-10 00:09:15

profh
Member
Registered: 2010-07-02
Posts: 159

Re: How to put TDataModule in DLL with Lazarus

@ab, thanks, and I will try later.

Offline

#13 2020-04-10 15:42:02

profh
Member
Registered: 2010-07-02
Posts: 159

Re: How to put TDataModule in DLL with Lazarus

@ab, AOG:
after recompiled sqlite3.c and ecc.c with -fPIC option, it worked.

thanks to both of you!

Offline

#14 2020-04-10 17:48:10

AOG
Member
Registered: 2014-02-24
Posts: 490

Re: How to put TDataModule in DLL with Lazarus

That is good to know. Thanks.
On Android, this is already standard.

Offline

Board footer

Powered by FluxBB