Dynamic dialogs

Example scripts and tips (replaces Old Scripts & Tips archive)

Moderators: Dorian (MJT support), JRL, Phil Pendlebury

Post Reply
User avatar
Grovkillen
Automation Wizard
Posts: 1009
Joined: Fri Aug 10, 2012 2:38 pm
Location: Bräcke, Sweden
Contact:

Dynamic dialogs

Post by Grovkillen » Mon Oct 15, 2018 7:10 pm

Hello,

I tried to fix a nagging problem I was facing with the column width not working for all users (the width was sometime to wide or too narrow). I was told that the column widths are not accessible through the dialog handler commands. But this software being what it is, the most versatile SW there is, I came up with a solution for my problem using WriteLn and Include.

Here's the idea exemplified. I hope more users will benefit from this. :)

Code: Select all

//LabelToVar doesnt have to contain a full dialog code
LabelToVar>DialogCode,TEMP
IncludeFromVar>TEMP
//I delete it if it exists just to show that it is in fact dynamic
IfFileExists>%SCRIPT_DIR%\dialog.scp
  DeleteFile>%SCRIPT_DIR%\dialog.scp
Endif>
//Since I'm using label to variable there cannot be a dialog1 existing in two places in the script file.. this string replace is just a workaround for that
StringReplace>TEMP,DialogX,Dialog1,TEMP
GoSub>RANDOMIZE_AND_REPLACE_STUFF
//Write the dialog script file
WriteLn>%SCRIPT_DIR%\dialog.scp,,TEMP
//Include it (if you compile as exe you shouldn't compile includes)
Include>%SCRIPT_DIR%\dialog.scp
//Show the dynamic dialog
Show>Dialog1,r

SRT>RANDOMIZE_AND_REPLACE_STUFF
  Random>100,RANDOM_LEFT
  Random>100,RANDOM_TOP
  StringReplace>TEMP,[RANDOM_LEFT],%RANDOM_LEFT%,TEMP
  StringReplace>TEMP,[RANDOM_TOP],%RANDOM_TOP%,TEMP
  StringReplace>TEMP,[USER_NAME],%USER_NAME%,TEMP
END>RANDOMIZE_AND_REPLACE_STUFF
 
/*
DialogCode:
Dialog>DialogX
object DialogX: TForm
  Left = 247
  Top = 97
  HelpContext = 5000
  BorderIcons = [biSystemMenu]
  Caption = 'TEMP'
  ClientHeight = 211
  ClientWidth = 476
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = True
  ShowHint = True
  OnTaskBar = False
  PixelsPerInch = 96
  TextHeight = 13
  object Label1: TLabel
    Left = [RANDOM_LEFT]
    Top = [RANDOM_TOP]
    Width = 32
    Height = 13
    Caption = '[USER_NAME]'
  end
end
EndDialog>DialogX
*/
You need to save the script for it to work.
Let>ME=%Script%

Running: 15.0.24
version history

User avatar
Grovkillen
Automation Wizard
Posts: 1009
Joined: Fri Aug 10, 2012 2:38 pm
Location: Bräcke, Sweden
Contact:

Re: Dynamic dialogs

Post by Grovkillen » Tue Oct 16, 2018 6:37 am

By accident I stumbled upon the fault that was causing problems with the column width. Depending on user settings the "pixels per inch" is not taken into account for column widths...
Let>ME=%Script%

Running: 15.0.24
version history

Post Reply
cron
Sign up to our newsletter for free automation tips, tricks & discounts