Graphic User Interfaces
The GUI capabilities discussed here are provided for those instances where the simple user input prompts are inadequate. Since building GUIs can be a lengthy process only some some general guidelines are presented in this tutorial. Several code examples can be found under the Script Examples menus.
The ArtSong™ scripting engine provides access to the same visual component library that ArtSong™ uses for its windows and dialogs; Borland®’s Visual Component Library™ (VCL). Using script you can create many of the common VCL objects such as forms, buttons, labels, etc. and establish mouse and keyboard event-handling using syntax very similar to the Object Pascal syntax used in Borland®’s Delphi™.
Only general guidelines are presented here. More info can be found in the accompanying example projects.
Creating Components
IMPORTANT: When creating forms make sure to provide the ‘Self’ as the argument; this will help ensure that forms are cleaned up properly when the script stops executing. This is especially important for non-modal forms.
myForm := TForm.Create(Self); // create form – owner is the ‘Self’
myForm.Width := 200; // set form properties
myForm.Height := 200;
myForm.Top := 100;
myForm.Left := 300;
myForm.ShowModal(); // Shows modal form
When creating components for placement on a form the ‘owner’ property of the component should be the form itself; this will ensure that the components get freed with the form. In order to display the component you will need to set its ‘parent’ property to the windowed component that this component is to be displayed in. The ‘parent’ component is responsible for displaying all its child components.
The position properties of components are always relative to the parent components.
// for non-form components the ‘Owner’ should be the form itself
myLabel := TLabel.Create(myForm);
myLabel.Caption := ‘This is a label’;
myLabel.Parent := myForm;
myButton := TBitBtn.Create(myForm);
myButton.Caption := ‘This is a button’;
myButton.Parent := myForm;
If ‘Panels’ (or other container components) are used to group components, than the ‘Panel’ should be assigned to the ‘Parent’ property for all components displayed on that panel.
myPanel := TPanel.Create(myForm);
myPanel.parent := myForm;
myButton := TButton.Create(myForm);
myButton.parent := myPanel; // button is displayed on panel
Event Handling
Most of the controls can have ‘events’ which are trigger by mouse clicking, key pressing etc. Script event-handlers by creating a procedure / subroutine and assigning it to the appropriate component event:
procedure DoClick(Sender)
begin
ShowMessage(‘Clicked’);
end;
myButton := TBitBtn.Create(myForm);
myButton.Caption := ‘This is a button’;
myButton.Parent := myForm;
myButton.OnClick := ‘DoClick’; // assign
|