VCP: Trick 1 – Allowing user to enable/disable button on template form by Hormon
This is the first article in the series about Viz Content Pilot Tips and Tricks. I decided to share with you some of the usefull tricks to be used in templates. Some of them you may find easy, some are more complicated or at least look that way. All of them I used in at my work to provide users with some functionalities which are not present in VCP and have to be programmed from scratch.
Since it was introduced Viz Content Pilot still uses same old (“shitty” :-) ) Delphi vcl controls. Not only they have very limited functionality but also are quite out of date. Vizrt team for instance has hidden some events for us like for example OnPaint event. Thus button control looks really terrible and we can’t do anything about it.
This series of articles (starting with this one) will focus on those tiny little enhancements that make template look better and be more functional.
Trick 1: Allowing user to enable / disable button on template form
The trick I’m going to show you was used in a very sophisticated template which was gathering data from Reuters feeds and some other sources. It was quering databases at specified intervals and updating values both on template form and on-air. It also allowed to display data on-air in many different ways (bar charts, line charts, data tables). Since lots of thing were going on underneath template form I faced necesity to turn on/off some action buttons on template form depending on a specific state template was in. Disabling/Enabling from code was easy but after few days operators asked me if I can reenable some buttons for them, because sometimes they need to query for data manually. And here comes the problem. “How should I do this when I have limited space left on template form? Also what would be the best way for the user to enable some buttons manually?”. I came up with the following idea.
If a user clicks on a button holding Control key – the enabled state of this button should be toggled. This approach is quite easy to use for the operator and requires exactly no additional space on template form. The implementation is also very easy. First we should add additional Static Image control to the form, make its size equal to the size of the button and place it underneath the button control. In this case I had buttons named with the following pattern: “btn” prefix followed by action name in “CamelCase”. I decided to keep this convention and name the background controls the same way: “bg” prefix followed by action name in “CamelCase”.
Next I had to implement MouseUp event handlers for both: button and background control. Unfortunatelly in delphi controls used in VCP there is literally no fancy way of cancelling Click event when it’s not supposed to be fired. Thus I had to move all my code inside MouseUp event handler. Here’s how I did it.
'---------------------------
Sub ButtonMouseUp(Sender, Button, Shift, X, Y)
Dim ctrl, ctrlName
ctrlName = Replace(Sender.Name, "btn", "bg")
ctrl = FindComponent(ctrlName)
If (Shift And 4) Then
Sender.Enabled = False
ctrl.Enabled = True
Else
'Here goes click event handler
End If
End Sub
'---------------------------
'---------------------------
Sub BackgroundMouseUp(Sender, Button, Shift, X, Y)
Dim ctrl, ctrlName
ctrlName = Replace(Sender.Name, "bg", "btn")
ctrl = FindComponent(ctrlName)
If (Not ctrl.Enabled) Then
If (Shift And 4 ) Then
Sender.Enabled = False
ctrl.Enabled = True
End If
End If
End sub
As you probably see I toggle enabled state for background control the oposite way than button control. So if button is enabled, background control is disabled and so on. This ensures only one event (button or background) will be fired and handled at a time. You may also notice that the number “4″ I’m seeking in the Shift state is a Control Key Code. So if Shift contains Control key the proper code is executed.
And that’s all. Try it out, maybe you’ll find it usefull and use it in one of your templates. Till next time.
GHTime Code(s): 9b530 nc
