VTW ConnectVTWEvent and script units

richhelvey

New member
When making a dynamic UI in template wizard, I can use ConnectVTWEvent() to assign events to buttons and whatnot.

Like so:
Code:
sub InitForm
     btn = CreateVTWComponent("TTWUniButton", [_TEMPLATE])
     ConnectVTWEvent [_scripter], btn, "OnClick", "ButtonClick"
end sub

sub ButtonClick(Sender)
        MsgBox("click")
end sub

However, if I'm using script units, I cannot figure out how to reference a sub or function inside that unit when using ConnectVTWEvent.

Like this (doesn't work)---
MAIN SCRIPT:
Code:
'USEUNIT Test_dynamicUI
sub InitForm
     btn = CreateVTWComponent("TTWUniButton", [_TEMPLATE])
     ConnectVTWEvent [_scripter], btn, "OnClick", "ButtonClick"
end sub

Test_dynamicUI UNIT SCRIPT:
Code:
'this code is inside the script unit
sub ButtonClick(Sender)
        MsgBox("click - in script unit")
end sub

Is what I'm trying to do even possible?

Thanks,
-Rich
 
The problem relies in that is not possible to assign to an event of a component a script that is in a script unit.
 
Just make a local wrapper function and assign it as event handler:
Code:
'USEUNIT Test_dynamicUI
sub InitForm
   btn = CreateVTWComponent("TTWUniButton", [_TEMPLATE])
   ConnectVTWEvent [_scripter], btn, "OnClick", "ButtonClick"
end sub

sub ButtonClick(Sender)
   [Test_dynamicUI].ButtonClick Sender
end sub
 
did you try the last suggestion? I think it can work but cant test it right now
Yes, but my aim is to make everything external so that it's cleaner and avoids the ping-pong that complicates everything...

My current problem is how to assign a sub that is in an external script to a button using the ConnectVTWEvent command.
I have tried many possibilities like these below, but I don't know how to format that, what is the syntax for that...

ConnectVTWEvent MainScript, myButton, "OnClick", [scriptUnit]."myButtonClick"
ConnectVTWEvent MainScript, myButton, "OnClick", ["scriptUnit.myButtonClick"]
ConnectVTWEvent MainScript, myButton, "OnClick", GetRef("scriptUnit.myButtonClick")
ConnectVTWEvent MainScript, myButton, "OnClick", "how to say here use the specific sub into the scriptUnit"
 
Back
Top