# Script Form {ref}`Script Form` is a opinionated, `TLazForm` that you can setup and run in a just a few lines. ```{figure} ../../images/basic_scriptform.png A very basic `TScriptForm` with 3 tabs ``` This page is only about the very base of `TScriptForm`. For information about pre-built panels you can find them on these pages: - {ref}`House Form` - - - - - ## TScriptForm Main type for the {ref}`TScriptForm`. - - - ## Built-in Callbacks {ref}`TScriptForm` has several built-in callbacks setup by default: - - - ### ScriptForm.OnClose ```pascal procedure TScriptForm.OnClose(sender: TLazObject; var closeAction: ELazFormCloseAction); ``` Callback called when the `TScriptForm.Form.OnClose` procedure. This ensures the script is terminated when you close the form. Closing the form programatically with `ScriptForm.Form.Close()` will also terminate your script by default if you don't want this you will need to do something similar to what {ref}`ScriptForm.OnStart` which does the following when it runs: ```pascal ScriptForm.Form.OnClose := nil; ScriptForm.Form.Close(); ``` - - - ### ScriptForm.OnStart ```pascal procedure TScriptForm.OnStart(sender: TLazObject); ``` This callback is ran on the `TScriptForm.Start.OnClick` procedure. By default, it's only used to close/hide the form and ensure that {ref}`ScriptForm.OnClose` doesn't run. The recommended usage for scripts would be to override this to setup your script variables when it runs before calling `inherited`, something like this: Example: ```pascal procedure TScriptForm.StartScript(sender: TLazObject); override; begin CurrentTask := ETask(Self.TaskSelector.GetItemIndex()); inherited; end; ``` - - - ## ScriptForm.Setup ```pascal procedure TScriptForm.Setup(caption: String = 'Script Form'; size: TPoint = [750, 500]; allowResize: Boolean = False); ``` Responsible for setting your TScriptForm up. This sets up the sekeleton of your TScriptForm ready to take in tabs. - - - ## ScriptForm.CreateTab ```pascal function TScriptForm.CreateTab(caption: String): TLazTabSheet; ``` Methods to create and add tabs to `TScriptForm`. This will create a new tab on the form and return it to you as the result so you add controls to it. Example: ```pascal {$I WaspLib/osrs.simba} var form: TScriptForm; selector: TCombobox; tab: TLazTabSheet; begin form.Setup(); tab := form.CreateTab('House'); selector := TLazComboBox.CreateEx(tab); form.Run(); end. ``` - - - ## ScriptForm.AddTab ```pascal procedure TScriptForm.AddTab(owner: Pointer); ``` Adds an already existing `TLazTabSheet` to the `TScriptForm`. - - - ## ScriptForm.Run ```pascal procedure TScriptForm.Run(); ``` Runs and shows your `TScriptForm` after it has been setup.