Modifying the constructor - SmartPlant Foundation - IM Update 44 - Customization & Programming - Hexagon

SmartPlant Foundation Customization

Language
English
Product
SmartPlant Foundation
Search by Category
Customization & Programming
SmartPlant Foundation / SDx Version
10

We need to modify the constructor method to pass in the parameters that are required by the parent class constructor: BaseSystemForm. Change Sub New like this:

Public Class DoSomethingGUI

Private mobjClientAPI As SPF.Client.APIs.Model.ClientAPI

Public Sub New(ByVal pobjSPFWindowsFormsClient As SPFWindowsFormsClient, ByVal pobjClientAPI As SPF.Client.APIs.Model.ClientAPI)

MyBase.New(pobjSPFWindowsFormsClient)

InitializeComponent()

mobjClientAPI = pobjClientAPI

Initialize()

End Sub

Private Sub Initialize()

Me.txtOBID.Text = mobjClientAPI.IObject.OBID

Me.txtName.Text = mobjClientAPI.IObject.Name

Me.txtDesc.Text = mobjClientAPI.IObject.Description

End Sub

End Class

Notice that the SPFWindowsFormsClient is passed in, and it is basically a reference to the entire Desktop Client. You can get to most everything from this reference. The ClientAPI class is also passed in, and you can find some valuable information in that object as well. The best practice is to always have an Initialize method that is called from the constructor. Any objects that are required on the form need to be stored as member variables so they can be accessed when required. We want the form to display some information from the object under the mouse. The context object is available in the base class of the ClientAPI with a property named 'IObject'. Like the Schema class of the same name, the IObject class has properties on it for UID, Name, and Description. Additionally, it has properties that are common to every SPF object like OBID, CreationDate, and TerminationDate. Using the properties we set the text boxes in the form with the correct values.