I use the old script engine, which is no longer supported by its creators and has some problems with memory leaks. It uses a function written in ASM to call from scripts in Delphi functions, and returns the result as an integer, then passes that integer as an unwritten parameter to another procedure, which translates it into the correct type.
This works fine for most things, but when the Delphi function return type was Variant, it loses memory because the variant is never deleted. Does anyone know how I can take an untyped parameter containing a variant and make sure that it will be disposed of properly? This will probably be due to some inline build.
procedure ConvertVariant(var input; var output: variant);
begin
output := variant(input);
asm
//what do I put here? Input is still held in EAX at this point.
end;
end;
EDIT: answer to Rob Kennedy's question in the comments:
AnsiString conversion works as follows:
procedure VarFromString2(var s : AnsiString; var v : Variant);
begin
v := s;
s := '';
end;
procedure StringToVar(var p; var v : Variant);
begin
asm
call VarFromString2
end;
end;
This works great and does not create memory leaks. When I try to do the same with the option as an input parameter, and assign the original Nullto the second procedure, memory leaks still occur.
Mostly options contain strings - a script is used to generate XML - and they got there by assigning a Delphi string to a variant in the Delphi function that calls this script. (Changing the return type of the function will not work in this case.)
source
share