[fpc-pascal] DLL call works on FPC 2.6.4 but not with D7

Jonas Maebe jonas.maebe at elis.ugent.be
Wed Jul 2 13:11:55 CEST 2014


On 02 Jul 2014, at 12:26, Virgo Pärna wrote:

> On Wed, 2 Jul 2014 11:23:33 +0200, Jonas Maebe <jonas.maebe at elis.ugent.be 
> > wrote:
>>
>> As has been mentioned earler in the thread, MyReturnStr itself is a
>> pchar.
>
>    Sorry, I had to recheck thred multiple times before I found it.  
> Initially
> he did not mention the type at all.

I know, that's why I initially also wrongly assumed that it was an  
ansistring and hence also proposed @MyReturnStr[1] in my first reply.

>    Anyway, if variable is of type PChar, then there is not reason to  
> take
> an address of first element to pass it to PChar. Passing wariable  
> itselt is
> much clearer.

I disagree. People make mistakes all the time with dynamic data  
structures, forgetting that they are implicit pointers (or getting run  
time errors when they change the type of a variable from a static into  
a dynamic one). Passing the address of the first element is however  
always correct. The only downside is that the index of the first  
element may change, although for strings it won't (unless you switch  
to {$zerobasedstrings}) and for arrays you could solve that with  
@MyReturnStr[low(MyReturnStr)] (in case you often replace arrays with  
one using a different lower bound -- but in that case, other code may  
break too).


Jonas
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20140702/d9524900/attachment.html>


More information about the fpc-pascal mailing list