THCXBarManagerServices=class
published
function CreateUserButton(aBar:integer; aCaption:string; aIconIndex:integer; aOnClick:TNotifyEvent):boolean;
end;
and
function THCXBarManagerServices.CreateUserButton(aBar: integer; aCaption: string; aIconIndex: integer; aOnClick: TNotifyEvent): boolean;
begin
//some code here
Item.OnClick:=aOnClick;
//some code here
end;
How to pass aOnCLick event from script. Script looks like:
procedure TestClick(Sender:TObject);
begin
//click
end;
procedure InitForm;
var BS:THCXBarManagerServices;
begin
//some code here
r:=BS.CreateUserButton(userbar,'Test',12,'TestClick');
//some code herr
end;
I agree that property is much better for this purpose. Another way I have tested is EventBroker.SetEvent. I declare event as string and in machine proc I have somethink like this:
procedure TatdxBarLibrary.__THCXBarManagerServicesCreateUserButton(AMachine: TatVirtualMachine);
var
AResult: variant;
ALink:TdxBarItemLink;
begin
with AMachine do
begin
ALink := THCXBarManagerServices(CurrentObject).IntCreateUserButton(VarToInteger(GetInputArg(0)),VarToStr(GetInputArg(1)),VarToInteger(GetInputArg(2)));
if ALink<>nil then begin
if Scripter.EventBroker.SetEvent(ALink.Item,'OnClick',VarToStr(GetInputArg(3)),Scripter,epReplaceCall)<>nil then
AResult:=true
else begin
Alink.Item.Free;
AResult:=false;
end;
end else
AResult:=false;
ReturnOutputArg(AResult);
end;
end;
DefineMethod is
With Scripter.DefineClass(THCXBarManagerServices) do
begin
DefineMethod('CreateUserButton',4,tkVariant,nil,__THCXBarManagerServicesCreateUserButton,false,0,'aBar: integer; aCaption: string; aIconIndex: integer; aOnClick: string');
end;
It works, but I have to be sure that this is good approach also. Can scripter work ok with this solution?