Forum > Beginners

DLL usable in Delphi?


Consider the following unit and library:

--- Code: ---unit support;

{$mode objfpc}{$H+}

  TSomeList = specialize TFPGList<some_type>;

--- End code ---

--- Code: ---library a_dll_for_delphi_developer;

{$mode delphi}{$H+}


function DoSomething: TSomeType;


--- End code ---

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?

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)

--- Code: ---function MyFunc(name: PChar)

--- End code ---
is good

--- Code: ---function MyFunc(const name: string)

--- End code ---
is not good

All my strings are AnsiStrings. Should I convert them to PChar then?


--- Quote from: py2pa on August 20, 2014, 11:13:35 pm ---All my strings are AnsiStrings. Should I convert them to PChar then?

--- End quote ---

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.


[0] Message Index

Go to full version