Set return value of dialog1 to dialoge2

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
nodochau
Pro Scripter
Posts: 131
Joined: Wed Jan 16, 2019 12:59 pm

Set return value of dialog1 to dialoge2

Post by nodochau » Mon Feb 10, 2020 7:21 pm

Hello All,
I have set two dialogs and try to get the return value from dialog1 (Edit property) and set it into dialog2 (Edit property). I have no success to do it. After I click Button A and B and I will have the variable name=AB
in dialog1. But I can not use that variable %name% to set into the Edit1object of dialog2.
I want AB to show in dialog2.
Please help. And please show me how to post code here :)
Here is my program:

Dialog>Dialog1
object Dialog1: TForm
Left = 2460
Top = 103
HelpContext = 5000
BorderIcons = [biSystemMenu]
Caption = 'CustomDialog'
ClientHeight = 205
ClientWidth = 586
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -14
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = True
ShowHint = True
OnTaskBar = False
PixelsPerInch = 120
TextHeight = 16
object Edit1: TEdit
Left = 192
Top = 41
Width = 194
Height = 24
TabOrder = 0
Text = 'Edit1'
end
object MSButton1: tMSButton
Left = 134
Top = 96
Width = 75
Height = 25
Caption = 'A'
TabOrder = 1
DoBrowse = False
BrowseStyle = fbOpen
end
object MSButton2: tMSButton
Left = 393
Top = 92
Width = 75
Height = 25
Caption = 'B'
TabOrder = 2
DoBrowse = False
BrowseStyle = fbOpen
end
object MSButton3: tMSButton
Left = 162
Top = 150
Width = 75
Height = 25
Caption = 'OK'
ModalResult = 1
TabOrder = 3
DoBrowse = False
BrowseStyle = fbOpen
end
object MSButton4: tMSButton
Left = 341
Top = 151
Width = 75
Height = 25
Caption = 'CANCEL'
TabOrder = 4
DoBrowse = False
BrowseStyle = fbOpen
end
end
EndDialog>Dialog1

Dialog>Dialog2
object Dialog2: TForm
Left = 2460
Top = 103
HelpContext = 5000
BorderIcons = [biSystemMenu]
Caption = 'CustomDialog'
ClientHeight = 205
ClientWidth = 586
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -14
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = True
ShowHint = True
OnTaskBar = False
PixelsPerInch = 120
TextHeight = 16
object Edit1: TEdit
Left = 208
Top = 62
Width = 177
Height = 24
TabOrder = 8
Text = 'Edit1'
end
object MSButton1: tMSButton
Left = 146
Top = 124
Width = 75
Height = 25
Caption = 'CONFIRM'
ModalResult = 1
TabOrder = 9
DoBrowse = False
BrowseStyle = fbOpen
end
object MSButton2: tMSButton
Left = 389
Top = 127
Width = 75
Height = 25
Caption = 'RESET'
ModalResult = 2
TabOrder = 10
DoBrowse = False
BrowseStyle = fbOpen
end
end
EndDialog>Dialog2

AddDialogHandler>Dialog1,MSButton1,OnClick,clickA
AddDialogHandler>Dialog1,MSButton2,OnClick,clickB
let>signal=0
show>dialog1,s1
if>s1=1
let>name=text
let>text=
let>dialog1.Edit1=text
ResetDialogAction>dialog1
endif
mdl>name
SetDialogProperty>dialog2,Edit1,Text,name
Show>dialog2,s2


SRT>clickA
GetDialogProperty>Dialog1,MSButton1,Caption,nameA
Gosub>signal condition
ConCat>text,nameA
let>dialog1.Edit1=text
ResetDialogAction>dialog1
let>signal=1
END>clickA

SRT>clickB
GetDialogProperty>Dialog1,MSButton2,Caption,nameB
Gosub>signal condition
ConCat>text,nameB
let>dialog1.Edit1=text
ResetDialogAction>dialog1
let>signal=1
END>clickB

SRT>signal condition
if>signal=0
let>text=
endif
END>signal condition

User avatar
JRL
Automation Wizard
Posts: 3497
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Re: Set return value of dialog1 to dialoge2

Post by JRL » Mon Feb 10, 2020 10:01 pm

First to set code to display properly in the forum, highlight the code then press the </> button located just above the text box.

With the code:
- Dialogs created using Macro Scheduler version 12 and beyond no longer need ResetDialogAction>
- You have created a variable named "Text". "Text" is the name of a dialog Edit box property. When you set the variable Text you rendered edit boxes unusable. Be careful not to name variables the same as Dialog objects or object properties.
- You don't set a dialog property using Let>. You use the SetDialogProperty function.

I've corrected your code below. Hope this helps.

Code: Select all

Dialog>Dialog1
object Dialog1: TForm
Left = 2460
Top = 103
HelpContext = 5000
BorderIcons = [biSystemMenu]
Caption = 'CustomDialog'
ClientHeight = 205
ClientWidth = 586
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -14
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = True
ShowHint = True
OnTaskBar = False
PixelsPerInch = 120
TextHeight = 16
object Edit1: TEdit
Left = 192
Top = 41
Width = 194
Height = 24
TabOrder = 0
Text = 'Edit1'
end
object MSButton1: tMSButton
Left = 134
Top = 96
Width = 75
Height = 25
Caption = 'A'
TabOrder = 1
DoBrowse = False
BrowseStyle = fbOpen
end
object MSButton2: tMSButton
Left = 393
Top = 92
Width = 75
Height = 25
Caption = 'B'
TabOrder = 2
DoBrowse = False
BrowseStyle = fbOpen
end
object MSButton3: tMSButton
Left = 162
Top = 150
Width = 75
Height = 25
Caption = 'OK'
ModalResult = 1
TabOrder = 3
DoBrowse = False
BrowseStyle = fbOpen
end
object MSButton4: tMSButton
Left = 341
Top = 151
Width = 75
Height = 25
Caption = 'CANCEL'
TabOrder = 4
DoBrowse = False
BrowseStyle = fbOpen
end
end
EndDialog>Dialog1
Dialog>Dialog2
object Dialog2: TForm
Left = 2460
Top = 103
HelpContext = 5000
BorderIcons = [biSystemMenu]
Caption = 'CustomDialog'
ClientHeight = 205
ClientWidth = 586
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -14
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = True
ShowHint = True
OnTaskBar = False
PixelsPerInch = 120
TextHeight = 16
object Edit1: TEdit
Left = 208
Top = 62
Width = 177
Height = 24
TabOrder = 8
Text = 'Edit1'
end
object MSButton1: tMSButton
Left = 146
Top = 124
Width = 75
Height = 25
Caption = 'CONFIRM'
ModalResult = 1
TabOrder = 9
DoBrowse = False
BrowseStyle = fbOpen
end
object MSButton2: tMSButton
Left = 389
Top = 127
Width = 75
Height = 25
Caption = 'RESET'
ModalResult = 2
TabOrder = 10
DoBrowse = False
BrowseStyle = fbOpen
end
end
EndDialog>Dialog2

AddDialogHandler>Dialog1,MSButton1,OnClick,clickA
AddDialogHandler>Dialog1,MSButton2,OnClick,clickB
let>signal=0
show>dialog1,s1
if>s1=1
let>name=vtext
let>vtext=
SetDialogProperty>Dialog1,Edit1,Text,vtext
//let>dialog1.Edit1=text
//ResetDialogAction>dialog1
endif
mdl>name
SetDialogProperty>dialog2,Edit1,Text,name
Show>dialog2,s2

SRT>clickA
GetDialogProperty>Dialog1,MSButton1,Caption,nameA
Gosub>signal condition
ConCat>vtext,nameA
SetDialogProperty>Dialog1,Edit1,Text,vtext
//let>dialog1.Edit1=text
//ResetDialogAction>dialog1
let>signal=1
END>clickA
SRT>clickB
GetDialogProperty>Dialog1,MSButton2,Caption,nameB
Gosub>signal condition
ConCat>vtext,nameB
SetDialogProperty>Dialog1,Edit1,Text,vtext
//let>dialog1.Edit1=text
//ResetDialogAction>dialog1
let>signal=1
END>clickB
SRT>signal condition
if>signal=0
let>vtext=
endif
END>signal condition

nodochau
Pro Scripter
Posts: 131
Joined: Wed Jan 16, 2019 12:59 pm

Re: Set return value of dialog1 to dialoge2

Post by nodochau » Tue Feb 11, 2020 11:49 am

Thank you so much JRL.

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