ghkweon / dwscript

Automatically exported from code.google.com/p/dwscript
0 stars 0 forks source link

Impossible to create an external function that returns a TStringList #289

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
The TStringList in dwsClassesLib is not actually a TStringList, but a class 
called TdwsStringList which reimplements its methods from scratch.  This means 
that it's not possible to write an external function that returns a TStringList 
into the script environment:

If it returns a native TStringList, the script methods don't work because 
they're expecting a TdwsStringList, and this can even corrupt memory.

If it returns a TdwsStringList, RegisterExternalObject fails because it looks 
up the class name and nothing called "TdwsStringList" is known to the script 
engine.

Similar issues exist for most of the other collection classes introduced in 
dwsClassesLib.

Original issue reported on code.google.com by masonwhe...@gmail.com on 16 Jul 2012 at 1:39

GoogleCodeExporter commented 8 years ago
Yes, well, the key issue here is that of memory management for the Objects[] 
property.

TStringList uses Pointers, so couldn't be used for placing script objects in it.
TdwsStringList uses reference-counted interfaces, but thus isn't compatible 
with TStringList.

All should be resolvable once the Delphi gets GC or ARC, but ad interim, I'm 
afraid, there will only be halfway solutions... One such solution if you don't 
need/want to expose the Objects[] property is to make a different 
implementation, that would use a TStringList internally.
However, even with that, you'll still have memory management issues to deal 
with with the TStringList itself (who should release it? when? etc.)

Original comment by zar...@gmail.com on 4 Sep 2012 at 9:54

GoogleCodeExporter commented 8 years ago

Original comment by zar...@gmail.com on 11 Jun 2013 at 7:21