From b1c084790fbbe44820d6805a5da4bc6c1ecac5c4 Mon Sep 17 00:00:00 2001 From: mattias Date: Mon, 21 Oct 2019 16:36:27 +0000 Subject: [PATCH] rtl: SetMethodProp: reuse callback if possible --- packages/rtl/typinfo.pas | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/packages/rtl/typinfo.pas b/packages/rtl/typinfo.pas index 20d5376..9f004d7 100644 --- a/packages/rtl/typinfo.pas +++ b/packages/rtl/typinfo.pas @@ -1418,7 +1418,19 @@ procedure SetMethodProp(Instance: TObject; PropInfo: TTypeMemberProperty; var cb: TJSFunction; begin - cb:=createCallback(Value.Data,Value.Code); + // Note: Value.Data=nil is allowed and can be used by designer code + if Value.Code=nil then + cb:=nil + else if isFunction(Value.Code) + and (TJSObject(Value.Code)['scope']=Value.Data) + and (isFunction(TJSObject(Value.Code)['fn']) or isString(TJSObject(Value.Code)['fn'])) + then + begin + // Value.Code is already a callback + cb:=TJSFunction(Value.Code); + end + else + cb:=createCallback(Value.Data,Value.Code); SetJSValueProp(Instance,PropInfo,cb); end;