1

In my Delphi (2010) code I have a class TImageItem, which I have exposed to DWScript via:

dwsUnit.ExposeRTTI(TypeInfo(TImageItem),[eoNoFreeOnCleanup, eoExposePublic]);

In dwsUnit I have declared a function to get a TImageItem from the Delphi side:

function GetImage: TImageItem;

and on the Delphi side:

procedure TFScript.dwsUnitFunctionsGetImageEval(info: TProgramInfo);
begin
    ...
    // (Item is a TImageItem and not nil)
    Info.ResultAsVariant := TdwsRTTIVariant.FromObject(Item);
end;

However, when I run a script starting like:

var Item: TImageItem;
Item := GetImage;
...

I get an EScriptError during the GetImage call with the message "Object already destroyed".

What am I doing wrong? Am I exposing the object or returning it incorrectly?

1 Answer 1

2

I don't know about ExposeRTTI, as I've never used it, but I would do it like this:

procedure TFScript.dwsUnitFunctionsGetImageEval(info: TProgramInfo);
begin
  ...
  // (Item is a TImageItem and not nil)
  Info.ResultAsVariant := Info.Vars[Info.ResultVars.TypeSym.Name].GetConstructor('Create', Item).Call.Value;
end;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.