Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2014-01

Can Delphi load a small function of a shared lib written in Free Pascal 2.6.2?

7 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

silvioprog

Hello,

On Windows, I'm trying to serialize an object to JSON in Delphi 7, using FPC functions linked in a shared lib.

I'm sendind a small demo in attached. To test it is very easy:

1. compile the libfpserializer.lpr file;
2. copy the generated lib to the demo/lazarus_ok folder;
3. copy the generated lib to the demo/delphi_bug folder;

Now, compile the Lazarus project in "lazarus_ok" folder, compile, run and see that it works fine. Now, compile the Delphi project in "delphi_bug" folder, compile, run and see a bizzare bug that kills the app.

So, in Delphi 7, its possible to consume a DLL written in Free Pascal?

Thank you!

Silvio Clécio My public projects - github.com/silvioprog
Michael Van Canneyt
to silvioprog
silvioprog wrote 13 lines
Hello, On Windows, I'm trying to serialize an object to JSON in Delphi 7, using FPC functions linked in a shared lib. I'm sendind a small demo in attached. To test it is very easy: 1. compile the libfpserializer.lpr file; 2. copy the generated lib to the demo/lazarus_ok folder; 3. copy the generated lib to the demo/delphi_bug folder; Now, compile the Lazarus project in "lazarus_ok" folder, compile, run and see that it works fine. Now, compile the Delphi project in "delphi_bug" folder, compile, run and see a bizzare bug that kills the app. So, in Delphi 7, its possible to consume a DLL written in Free Pascal?

You cannot mix Delphi objects with FPC objects.

They have a different memory layout, the RTTI is different etc. So what you try to do is not possible.

Michael.

Michael Van Canneyt
to Michael Van Canneyt
Michael Van Canneyt wrote 25 lines
On Thu, 16 Jan 2014, silvioprog wrote: > Hello, > On Windows, I'm trying to serialize an object to JSON in Delphi 7, using > FPC functions linked in a shared lib. > > I'm sendind a small demo in attached. To test it is very easy: > > 1. compile the libfpserializer.lpr file; > 2. copy the generated lib to the demo/lazarus_ok folder; > 3. copy the generated lib to the demo/delphi_bug folder; > > Now, compile the Lazarus project in "lazarus_ok" folder, compile, run and > see that it works fine. Now, compile the > Delphi project in "delphi_bug" folder, compile, run and see a bizzare bug > that kills the app. > > So, in Delphi 7, its possible to consume a DLL written in Free Pascal? You cannot mix Delphi objects with FPC objects. They have a different memory layout, the RTTI is different etc. So what you try to do is not possible.

I have somewhere a version of TJSONStreamer which uses SuperObject to write the JSON. If you want I can try to dig it up somewhere.

Michael.

silvioprog
to Michael Van Canneyt: You cannot mix Delphi objects with FPC objects. They have a different memory layout, the…

2014/1/16 Michael Van Canneyt

Show quoted text 27 lines
On Thu, 16 Jan 2014, silvioprog wrote: > Hello, > On Windows, I'm trying to serialize an object to JSON in Delphi 7, using > FPC functions linked in a shared lib. > > I'm sendind a small demo in attached. To test it is very easy: > > 1. compile the libfpserializer.lpr file; > 2. copy the generated lib to the demo/lazarus_ok folder; > 3. copy the generated lib to the demo/delphi_bug folder; > > Now, compile the Lazarus project in "lazarus_ok" folder, compile, run and > see that it works fine. Now, compile the > Delphi project in "delphi_bug" folder, compile, run and see a bizzare bug > that kills the app. > > So, in Delphi 7, its possible to consume a DLL written in Free Pascal? > You cannot mix Delphi objects with FPC objects. They have a different memory layout, the RTTI is different etc. So what you try to do is not possible. Michael.

:(

I think I saw a good news in the following e-mail, I will reply there ...

Silvio Clécio My public projects - github.com/silvioprog
silvioprog
to Michael Van Canneyt: I have somewhere a version of TJSONStreamer which uses SuperObject to write the JSON. If…

2014/1/16 Michael Van Canneyt

Show quoted text 34 lines
On Thu, 16 Jan 2014, Michael Van Canneyt wrote: > > On Thu, 16 Jan 2014, silvioprog wrote: > >> Hello, >> On Windows, I'm trying to serialize an object to JSON in Delphi 7, using >> FPC functions linked in a shared lib. >> >> I'm sendind a small demo in attached. To test it is very easy: >> >> 1. compile the libfpserializer.lpr file; >> 2. copy the generated lib to the demo/lazarus_ok folder; >> 3. copy the generated lib to the demo/delphi_bug folder; >> >> Now, compile the Lazarus project in "lazarus_ok" folder, compile, run >> and see that it works fine. Now, compile the >> Delphi project in "delphi_bug" folder, compile, run and see a bizzare >> bug that kills the app. >> >> So, in Delphi 7, its possible to consume a DLL written in Free Pascal? >> > > You cannot mix Delphi objects with FPC objects. > > They have a different memory layout, the RTTI is different etc. > So what you try to do is not possible. > I have somewhere a version of TJSONStreamer which uses SuperObject to write the JSON. If you want I can try to dig it up somewhere. Michael.

Very good friend. I want, and it will be very useful to me. Thank you! :)

Silvio Clécio My public projects - github.com/silvioprog
hinst
to silvioprog

I suggest you use COM interfaces to use FPC objects from Delphi code. While FPC class instance memory layout differs from Delphi class instance memory layout, COM interface instances should have identical memory layouts; so they should be accessible from Delphi code

17.01.2014, 04:31, "silvioprog" :

Show quoted text 35 lines
2014/1/16 Michael Van Canneyt > On Thu, 16 Jan 2014, Michael Van Canneyt wrote:> On Thu, 16 Jan 2014, silvioprog wrote: >>> Hello, >>> On Windows, I'm trying to serialize an object to JSON in Delphi 7, using FPC functions linked in a shared lib. >>> >>> I'm sendind a small demo in attached. To test it is very easy: >>> >>> 1. compile the libfpserializer.lpr file; >>> 2. copy the generated lib to the demo/lazarus_ok folder; >>> 3. copy the generated lib to the demo/delphi_bug folder; >>> >>> Now, compile the Lazarus project in "lazarus_ok" folder, compile, run and see that it works fine. Now, compile the >>> Delphi project in "delphi_bug" folder, compile, run and see a bizzare bug that kills the app. >>> >>> So, in Delphi 7, its possible to consume a DLL written in Free Pascal? >> >> You cannot mix Delphi objects with FPC objects. >> >> They have a different memory layout, the RTTI is different etc. >> So what you try to do is not possible. > > I have somewhere a version of TJSONStreamer which uses SuperObject to write the JSON. > If you want I can try to dig it up somewhere. > > Michael. Very good friend. I want, and it will be very useful to me. Thank you! :) -- Silvio Clécio My public projects - github.com/silvioprog , _______________________________________________ fpc-pascal maillist  -   http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
silvioprog
to hinst

2014/1/17 hinst

I suggest you use COM interfaces to use FPC objects from Delphi code. While FPC class instance memory layout differs from Delphi class instance memory layout, COM interface instances should have identical memory layouts; so they should be accessible from Delphi code

Thank you very much! I'll see it too.

Silvio Clécio My public projects - github.com/silvioprog