Recent

Author Topic: DLL usable in Delphi?  (Read 3541 times)

py2pa

  • New Member
  • *
  • Posts: 11
DLL usable in Delphi?
« on: August 20, 2014, 10:11:37 pm »
Consider the following unit and library:

Code: [Select]
unit support;

{$mode objfpc}{$H+}

type
  TSomeList = specialize TFPGList<some_type>;

Code: [Select]
library a_dll_for_delphi_developer;

{$mode delphi}{$H+}

uses
  support;

function DoSomething: TSomeType;

exports
  DoSomething;

end.

Now, if I change the directive in the unit to {$mode delphi}{$H+} (which for my purpose seems the most sensible thing to do), the compiler rejects the identifier "specialize". So, I change the directive back to objfpc mode and create the .dll. My question is: will the Delphi developer be able to use this library without problems?

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2770
    • havefunsoft.com
Re: DLL usable in Delphi?
« Reply #1 on: August 20, 2014, 10:57:34 pm »
They will be able to use just fine as long as your library exported functions will not use following types:
* strings (ansi,unicode) (wideStrings could be ok)
* classes or objects (using com interfaces is ok)
* dynamic arrays (using open arrays could be ok, but undesired. using pointer types is ok)
thus:
Code: [Select]
function MyFunc(name: PChar)
is good
Code: [Select]
function MyFunc(const name: string)
is not good

py2pa

  • New Member
  • *
  • Posts: 11
Re: DLL usable in Delphi?
« Reply #2 on: August 20, 2014, 11:13:35 pm »
All my strings are AnsiStrings. Should I convert them to PChar then?

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: DLL usable in Delphi?
« Reply #3 on: August 21, 2014, 02:40:38 am »
All my strings are AnsiStrings. Should I convert them to PChar then?

Yes at least. There is one more think to take care, there shouldn't be any memory allocation inside the dll at all. You force the calling application provide you with a buffer long enough to hold the result you want to pass. Simple passing around pchars instead of ansistrings is not enough.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

 

TinyPortal © 2005-2018