|
#1
|
||||
|
||||
FMXInno: Hidden Features Revealed
1) Today, I unlock the feature 'Runtime Scripts' for FMXInno for general use.
So, what are 'Runtime Scripts'? They are scripts that run at runtime without needing to be compiled at compile-time. This means that once you compile your Setup, you don't need to recompile it to apply changes made in 'Runtime Scripts'. Enough explanations, let's dive into a simple example: Here, I use the file extension '.fxs' for Runtime Scripts, but you can use whatever you want: '.pas', '.iss', '.txt', etc. Code:
Test_1.fxs ------------------------------------------- program Test1CreateRect; // This line is optional, so you can get rid of it. var ARect: FRectangle; procedure CleanUpRect; begin ARect := nil; end; begin ARect := InitRectangleHandle; ARect.FCreate(FMXFormHandle); ARect.SetBounds(200, 90, 250, 250); ARect.FillColor(ALRed); AExternalObj := ARect.Handle; end. Code:
Example.iss ------------------------------------------- var ARuntimeScript: FRuntimeScript; FirstRun : Boolean; AExternalObj: TFMXObject; procedure ABtnOnClick(Sender: TObject); begin if not FirstRun then begin // Get the handle of the external object that was created with the external script. AExternalObj := ARuntimeScript.GetRegisteredLongIntVar('AExternalObj'); // Call for cleanup. ARuntimeScript.CallProcFromScriptNoVar('CleanUpRect'); // Remove the external object from FMXForm as well. FMXForm.RemoveObject(AExternalObj); end; ARuntimeScript.CompileAndRun; FirstRun := False; end; Code:
procedure InitializeWizard(); begin { FMX Form } FMXForm.FCreateFluent(WizardForm.Handle, False, False, 0.96, 0); { ABtn } ABtn.FCreate(FMXForm.Handle); ABtn.Text('&Run'); ABtn.OnClick(@ABtnOnClick); { ARuntimeScript } ARuntimeScript.FCreate(ExpandConstant('{src}\_Scripts\Test_1.fxs')); ARuntimeScript.RegisterLongIntConst('FMXFormHandle', FMXForm.Handle); ARuntimeScript.RegisterLongIntVar('AExternalObj', 0); end; 2. And make some changes to the Runtime Script and smash the 'Run' button to see the changes. Code:
// ARect.FillColor(ALRed); ARect.FillColor(ALGreen); Code:
Test_1.fxs ------------------------------------------- var ARect, ARect2: FRectangle; begin ARect := InitRectangleHandle; ARect.FCreate(FMXFormHandle); ARect.SetBounds(80, 90, 200, 200); ARect.FillColor(ALRed); ARect2 := InitRectangleHandle; ARect2.FCreate(FMXFormHandle); ARect2.SetBounds(360, 90, 200, 200); ARect2.FillColor(ALBlue); ... end. * FMXInno has supported runtime scripts for quite a while with 'Lua'. Some may not be familiar with 'Lua', so i didn't promote it. On the other hand, 'FRuntimeScript' is Pascal, so everyone who uses InnoSetup can use this without any doubt. [*] Built-In Features / Functions / Constants / Variables:
[*] Register Custom Types: Code:
Example.iss ------------------------------------------- ARuntimeScript.RegisterType('TDummyRec', 'record' +#13#10+ ' PosX: Integer;' +#13#10+ ' PosY: Integer;' +#13#10+ 'end;'); ARuntimeScript.RegisterType('TsNum', 'Single'); Test_1.fxs ------------------------------------------- var ShippingFees: TsNum; ADummyRec: TDummyRec; [*] Load External Libraries (DLLs): You can call external DLLs inside runtime scripts in three different ways, -- Supported flags: 'stdcall', 'cdecl', and 'delayload'. 1. System Libs: 2. Libs from custom path: 3. I've added three special constants to runtime scripts, but you need to define them manually first. (a) 'Src': (b) 'App': (c) 'Tmp': (d) You can also use 'files:' to define the path. (e) Added built-in support for 'CreateCallback' function. [*] Call a function/procedure declared in Runtime Scripts through InnoSetup: There are two ways to call a function/procedure declared in Runtime Scripts via InnoSetup. (1) Without Parameters: (2) With Parameters: [*] Register InnoSetup's function/procedure and use them in Runtime Script: You can register functions/procedures for Runtime Scripts that have been declared in the InnoSetup (.iss). 1. At the moment, it doesn't accept any parameters. 2. You have to use the Callback function. Code:
Example.iss ------------------------------------------- type TDummyFunc2 = function: Integer; function XWrapNoVarFuncNew(Callback: TDummyFunc2): Longword; external 'XWrapNoVar@files:FMXInno.dll stdcall delayload'; function GetValueFromInnoSetup: Integer; begin Result := 69; end; procedure InnoMsgProc; var LNum: Longint; begin MsgBox('Hi', mbInformation, MB_OK); end; procedure InitializeWizard(); begin ... ARuntimeScript.RegisterProcNoVar(XWrapNoVarProc(@InnoMsgProc), 'procedure InnoMsgProc;'); ARuntimeScript.RegisterProcNoVar(XWrapNoVarFuncNew(@GetValueFromInnoSetup), 'function GetValueFromInnoSetup: Integer;'); ... end; Code:
Test_1.fxs ------------------------------------------- program Test7RegisterProc; var LuckyNum: Integer; procedure DoIt; begin InnoMsgProc(); end; begin LuckyNum := GetValueFromInnoSetup(); DoIt; end. [*] PreProcessor and Include Files: Runtime scripts support preprocessors and include files. Code:
Test_1.fxs ------------------------------------------- program Test10aIncludeFiles; // This line is optional, so you can get rid of it. {$DEFINE WHO_ARE_YOU} {$I ".\_Scripts\Test_10b.fxs"} var S: String; begin {$IFDEF WHO_ARE_YOU} S := 'Mr. BLACKFIRE'; {$ELSE} S := 'Mr/Ms/Mrs. Nobody'; {$ENDIF} SayHi(S); end. [*] Syntax Highlighting in the Text Editor: Open the '.fxs' file in your favorite text editor or IDE and select the file syntax as 'Pascal'. Now you're good to go. . |
Sponsored Links |
Thread Tools | |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
FMXInno - Windows Fluent Design Installer UI for Inno | BLACKFIRE69 | Conversion Tutorials | 867 | 18-11-2024 14:20 |
FMXInno - Discussion / Q&A Hub : Ask Away! | BLACKFIRE69 | Conversion Tutorials | 13 | 15-02-2024 18:37 |
Hidden & Dangerous 2 cd2dvd help | insekticid | PC Games | 22 | 06-09-2005 17:20 |
Xecuter3 features | Pop Smith | XBox Games | 4 | 23-05-2004 08:42 |