TrueGui Help
User Objects

Glossary Item Box

 

Introduction

User objects are a very powerful feature of the TrueGUI interface system. User objects are created by your application program and reside on the client-side PC. Once created, user objects can contain any type of data, similar to the Visual Basic variant type. User objects are actually references to any Object defined by the .NET framework or by any other assembly. Third-party controls and interfaces may, for instance, define specific data structures necessary to the functionality of their program. You can create any of these defined objects and reference all the fields, properties and methods by name. Advanced users can write functional modules in C# or Visual Basic (or any other language that supports the .NET framework), and then fully access the class objects inside these modules by name. 

 

Versatility 

You have already become familiar with user objects in a very basic way if you have worked with previous versions of TrueGUI. The command: 

MyForm = new Form1()

 

creates a user object named MyForm that references the instance of Form1 that was created by the new operation. You then reference that form instance using the MyForm symbol. You would show the form and set the text caption by the following commands: 

MyForm.Show()

MyForm.Text = `A New TitleBar`

 

Beyond this simple example, user objects can be used to contain any form of data. Take the following sequence for example: 

X = 150               create a new user object named X and assigns the value of 150 to it
button1.Width = X     set button1's Width to the value of X (currently 150)
X = `New Button`      change the value of X to a string
button1.Text = X      set the label of button1 to X (`New Button`)
Y = new Regex()       create a new Regex object (.NET regular expression) and uses Y to refer to it.
X = null              set user object X to a null value which releases it and the object it was referencing

 

Saving event data objects 

Once a user object is reassigned to a different object, the previous object is subject to garbage collection if it is no longer referenced by any other variable in the program. This means that a user object can be used to hold an object and keep it from being released by the garbage collector. For example, the EventArgs data block that is associated with each event will be released automatically once you request the following event because the TrueGui.EventData will be changed to reference the next EventArgs data block associated with the next event. If you wanted to keep an EventArgs data block active for future reference, you could assign it to a new (or existing) user object as follows: 

earg = EventData

 

The earg symbol can then be used to reference the EventArgs data block that was active when the above command was executed. The event data will remain available until the earg symbol is reassigned or disposed of by setting it to NULL. If, for instance, the event was a KeyDown event, the event data block would be of type KeyEventArgs and one of its properties would be KeyCode, that is used to store the keyboard of the key that was pressed. At any point in the program, even after several events had been processed following the KeyDown event, you could still retrieve the keyboard code by issuing the statement earg.KeyCode? because the event data block would be kept active by the user object reference. Another way to look at it would be that the EventData block would be "stored" in the new earg user object until released by setting earg to another object or to NULL.

 

Creating user object arrays and collections 

Arrays of any type of object may be created and assigned to user objects as well as simple objects. Take the following command sequence: 

AS = new String[50]          create an array of 50 strings which can be accessed via AS[0] thru AS[49]
AS[0] = `ABCDE`              set the first string element to ABCDE
AS[34] = item1.Text          store the text from item1 into the 35th string in the array
AS[5] = (label1 + `abc`)     expressions are legal here too
AS[7]?                       deliver the 8th string in the array back to the application program
AS = null                    release the string array and undefines the symbol "AS"