TElectronBrowserWindow
Description
Below is a list of the most important properties and methods for TElectronBrowserWindow
. This component allows the creation of multiple application windows, which can be linked to forms or other sources.
Designtime | Runtime |
Properties for TElectronBrowserWindow
Property | Description |
---|---|
FormClass: TFormClass | Sets the form class of the TElectronBrowserWindow . |
FullScreen: Boolean | Setting it to true will open the window in fullscreen. |
FullScreenable: Boolean | Determines if the window can be set to fullscreen by the user or not. |
IconPath: string | Sets the path to the icon. |
IconURL: string | Base64 encoded string that represents the icon. |
Kiosk: Boolean | Setting it to true will open the window in kiosk mode. |
MaxHeight: Integer | Sets the maximum height of the window. |
MaxWidth: Integer | Sets the maximum width of the window. |
MinHeight: Integer | Sets the minimum height of the window. |
MinWidth: Integer | Sets the minimum width of the window. |
Resizable: Boolean | Sets the resizability of the window. |
Methods for TElectronBrowserWindow
Property | Description |
---|---|
Close | Method to close the window. |
ForceClose | Method to force the closing of the window. |
Hide | Method to hide the window. |
LoadFromURL(URL: string) | Method to load from the given URL . It can be a URL or a path to a local file too. |
SendMessage(AMessage: string) | Method to send message to window. |
SendMessage(AMessage: JSValue) | Method to send message to the window. |
SendMessage(Channel: string; AMessage: string) | Method to send message to a channel. |
SendMessage(Channel: string; AMessage: JSValue) | Method to send message to a channel. |
Show | Method to show the window. |
ShowModal | Method to show the window as a modal It blocks the parent window. |
Events for TElectronBrowserWindow
Property | Description |
---|---|
OnActivate | Triggers when the window gains focus. |
OnClose | Triggers when the window closes. |
OnDeactivate | Triggers when the window loses focus. |
OnExitFullScreen | Triggers when the window exits fullscreen mode. |
OnFullScreen | Triggers when the window enters fullscreen mode. |
OnHide | Triggered when the window gets hidden. |
OnMaximize | Triggers when the window is maximized. |
OnMessage | Triggers when a message has been sent from the window to the parent window (= the form that contains the TElectronBrowserWindow instance). |
OnMinimize | Triggers when the window is minimized. |
OnResize | Triggers when the window is resized. |
OnShow | Triggers when the window is shown. |
Multiple windows using forms
Forms that are added to the project can be used as a source for the page to be shown in the window. In order to achieve this, a few steps have to be made:
- First of all the
**project.dpr**
file needs to be prepared to handle the routing of the forms. Add theWEBLib.WebTools
unit to theuses
list. After that, the code that is responsible for starting the application needs to be modified to the code below. - Whenever a new form is added to the project, it needs to be registered in the
initialization
section. - And for the last step, the form class needs to be assigned to the correct TElectronBrowserWindow instance. To do this, first the unit that contains the form has to be added to the uses list.
For example: We would like to use the TForm2
from Unit2
in Unit1
. Then in the uses list of Unit1
add Unit2
.
After this, in the form's OnCreate
event we can assign the form class to the TElectronBrowserWindow with the code below.
From now on, whenever ElectronBrowserWindow1.Show
is called, it creates the window for us automatically.
Multiple windows using other sources
An HTML file or a link to a website can also be used inside a TElectronBrowserWindow
. In this case the only necessary step is to call the URL
load method in the OnCreate
event of the form.
Showing a window
To show the window after its content had been set, simply call Show
or ShowModal
. The expected behaviour is that showing a modal window will block the parent window until the modal itself gets closed. On macOS
this modal window is a sheet that is attached to the parent window, and since it's blocking the parent from closing, it also blocks the whole application from closing. Keep in mind to always provide a way to the user to close the modal window.