Contents
Parent page: DelphiScript Overview of Graphical ComponentsThe scripting system handles two types of components: Visual and Non-visual components. Visual components are used to build the user interface and the non-visual components are used for different tasks, such as the
Both types of components appear at design time but non visual components are not visible at runtime. Components from the Tool Palette panel are object oriented and have the three following items:
A Property is a characteristic of an object that influences either the visible behavior or the operations of this object. For example, the Visible property determines whether this object can be seen or not on a script form. An Event is an action or occurrence detected by the script. In a script, the programmer writes code for each event handler designed to capture a specific event such as a mouse click. A Method is a procedure that is always associated with an object and defines the behavior of an object. All script forms have one or more components. Components usually display information or allow the user to perform an action. For example, a Any combination of components can be placed on a form, and while the script is running, a user can interact with any component on a form. It is the programmer's task to decide what happens when a user clicks a button or changes text in an The Scripting system supplies a number of components that can be used to create complex user interfaces for scripts. To place a component on a form, locate its icon on the Tool Palette panel and double-click it. This action places a component on the active form. The visual representation of most components is set with their properties. A component is initially placed in a default position on the form, but can be repositioned (dragged) and resized (stretched) as required. You can also change the size and position later using the Object Inspector. When a component is dropped onto a form, the Scripting system automatically generates code necessary to use the component, and updates the script form. Only the properties need to be set and event handler code implemented to use the desired methods to get the component on the form working. Designing Script FormsA script form is designed to interact with the user within the environment. Designing script forms is the core of visual development. In practice, all components placed on a script form and each property that is set is stored in a file describing the form (a When working with a script form and its components, all of the element properties can be inspected and modified using the Object Inspector panel. You can select more than one component by shift-clicking on the components, or by dragging a selection rectangle around the components on the form. A script form has a title (the Creating a New Script FormWith a script project open, right click on a project in the Projects panel, click on the Add New to Project item in the pop-up context menu and choose a Delphi Script Form item. A new script form will open with the default name of Displaying a Script FormA script needs to have a procedure that displays the form when the script form is executed. Within this procedure the ShowModal example:
The The ModalResult Example:
You could also set the When the user clicks either button on this script form, the dialog box closes. There is no need to call the Note that if you wish to set the form's Accepting Input from the UserOne of the common components that can accept input from the user is the The example below illustrates the process when user clicks on the button after typing something in the edit box. If the user did not type anything in the edit component (blank), the event handler responds with a warning message.
Note that a user can shift the dialog's input focus using the Tab key or by clicking on another control on the form. Responding to EventsWhen a button on a form or a component is clicked, the Scripting System responds by receiving an event notification from Altium Designer and calling the appropriate event handler method. See also Writing Event HandlersEach component in a form script has a set of event names, and these are used by script event handlers that determine how the script will react to user actions in Altium Designer. For instance, when a user clicks a button on a form, Altium Designer sends a message to the script and the script reacts to this new event. If the The code to respond to events is normally contained in DelphiScript event handlers, and all components have a set of events that they can react on. For example, all clickable components have an In summary, an event is a link between an occurrence in Altium Designer, such as clicking a button, and a piece of code that responds to that occurrence. The responding code is an event handler. This code modifies property values and calls methods. Component's PropertiesTo see a list of properties for a component, select a component and activate the Properties tab in the Object Inspector panel. Component EventsTo see a list of events a component can react on, select a component and activate the Events tab in the Object Inspector panel. To create an event handling procedure, select the event you want the component to react to and double click the event name — the scripting system will automatically insert the event handler framework code. For by way of example, select the If a button has a In a summary, select a button component either on the form or by using the Object Inspector panel, select the Events page and double click on the right side of the OnClick event and a new event handler will appear in the script. Alternatively, double click on the button itself and the scripting system will add a handler for this Component MethodsTo see a list of methods for a component, see the Component Reference document. Dropping Components on a Script FormTo use components from the Tool Palette panel in a script, a script form needs to exist before components can be dropped on the form. Normally when components are dropped on a script form, these objects do not need to be created or destroyed — the script form does this automatically. The scripting system also automatically generates the code necessary to use a component and updates the script form. Then it's just a matter of setting the properties, putting code in event handlers and using methods as necessary to implement a working script form. Creating Components in a ScriptComponents can be directly created or destroyed in a script by passing a Customizing Script FormsThe essential points for customizing script forms are:
Refreshing Script Forms and ComponentsWhen the surface of a script form becomes out of date, where for example, the controls are not updated or repainted, then the controls can look frozen or corrupted — this might be due to intensive background processing from that script. The StatusBar component and its Update method Example:
The above code snippet is from the |
|