Technical support and scripting issues
Moderators: JRL, Dorian (MJT support)
-
hagchr
- Automation Wizard
- Posts: 331
- Joined: Mon Jul 05, 2010 7:53 am
- Location: Stockholm, Sweden
Post
by hagchr » Sun Sep 20, 2015 7:54 pm
Hi, I have tried to illustrate a problem below. In the simplified example I want pressing the letter k to trigger a message. If I call an SRT containing the onEvent then it gets activated and works fine. If I call the same SRT, not directly, but via a Dialog Button / DialogHandler then nothing happens? What am I missing? Focus problem?
Code: Select all
Gosub>CreateDialog
Input>Alternative,Message,1
//
//onEvent - 1 direct via SRT, 2 via Dialog then SRT
If>Alternative=1
Gosub>KeyPress
Else
Show>Dialog1
AddDialogHandler>Dialog1,MSButton1,onClick,tmpPress
Endif
//
Label>Main
Wait>0.1
Goto>Main
//
SRT>KeyPress
OnEvent>KEY_DOWN,k,0,Greeting
END>KeyPress
//
SRT>tmpPress
CloseDialog>Dialog1
Gosub>KeyPress
END>tmpPress
//
SRT>Greeting
MDL>Hello, you pressed k!
EXIT
END>Greeting
//
SRT>CreateDialog
LabelToVar>Dialog,Dialog
IncludeFromVar>Dialog
Let>Message=Enter 1 or 2. then trigger with letter k%CRLF%(1. SRT directly, 2 via Dialog Button then SRT)
END>CreateDialog
//
/*
Dialog:
Dialog>Dialog1
object Dialog1: TForm
Left = 247
Top = 96
HelpContext = 5000
BorderIcons = [biSystemMenu]
Caption = 'CustomDialog'
ClientHeight = 185
ClientWidth = 200
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 MSButton1: tMSButton
Left = 63
Top = 56
Width = 75
Height = 65
Caption = 'Click Me to Proceed!'
TabOrder = 0
WordWrap = True
DoBrowse = False
BrowseStyle = fbOpen
end
end
EndDialog>Dialog1
*/
-
JRL
- Automation Wizard
- Posts: 3532
- Joined: Mon Jan 10, 2005 6:22 pm
- Location: Iowa
Post
by JRL » Mon Sep 21, 2015 4:10 pm
hagchr,
Exploring your problem it seems there is a problem with calling the OnEvent> using a dialog event handler. I simplified your code above in an attempt to isolate what was going on and to remove as many possible complications as possible. If you run the following in the editor so that the breakpoint can be used you'll see that the tmpPress subroutine is aborted at the OnEvent line and the OnEvent line is not processed.
I've submitted a bug report.
Dick
Code: Select all
Dialog>Dialog1
object Dialog1: TForm
end
EndDialog>Dialog1
AddDialogHandler>Dialog1,,onShow,tmpPress
Show>Dialog1
//
Label>Main
Wait>0.1
Goto>Main
//
SRT>tmpPress
**BREAKPOINT**
OnEvent>KEY_DOWN,k,0,Greeting
MDL>This will not display since the OnEvent breaks out of the subroutine.
CloseDialog>Dialog1
END>tmpPress
//
SRT>Greeting
MDL>Hello, you pressed k!
EXIT
END>Greeting
-
hagchr
- Automation Wizard
- Posts: 331
- Joined: Mon Jul 05, 2010 7:53 am
- Location: Stockholm, Sweden
Post
by hagchr » Mon Sep 21, 2015 4:18 pm
Hi, many thanks for looking at it. I will find a different route until there is a solution.
-
JRL
- Automation Wizard
- Posts: 3532
- Joined: Mon Jan 10, 2005 6:22 pm
- Location: Iowa
Post
by JRL » Tue Sep 22, 2015 9:03 pm
hagchr wrote:I will find a different route until there is a solution.
I would use a variable as a flag to determine when the event runs and when it doesn't. My version of your code would look like this:
Code: Select all
OnEvent>KEY_DOWN,k,0,Greeting
Let>KeyPressFlag=0
//
Gosub>CreateDialog
//
AddDialogHandler>Dialog1,MSButton1,onClick,tmpPress
Show>Dialog1
//
Label>Main
Wait>0.1
Goto>Main
//
SRT>tmpPress
Let>KeyPressFlag=1
CloseDialog>Dialog1
END>tmpPress
//
SRT>Greeting
If>KeyPressFlag=1
MDL>Hello, you pressed k!
EXIT
EndIf
END>Greeting
//
SRT>CreateDialog
LabelToVar>Dialog,Dialog
IncludeFromVar>Dialog
END>CreateDialog
//
/*
Dialog:
Dialog>Dialog1
object Dialog1: TForm
Left = 247
Top = 96
HelpContext = 5000
BorderIcons = [biSystemMenu]
Caption = 'CustomDialog'
ClientHeight = 185
ClientWidth = 200
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 MSButton1: tMSButton
Left = 63
Top = 56
Width = 75
Height = 65
Caption = 'Click Me to Proceed!'
TabOrder = 0
WordWrap = True
DoBrowse = False
BrowseStyle = fbOpen
end
end
EndDialog>Dialog1
*/
-
hagchr
- Automation Wizard
- Posts: 331
- Joined: Mon Jul 05, 2010 7:53 am
- Location: Stockholm, Sweden
Post
by hagchr » Wed Sep 23, 2015 8:14 am
That will work perfectly for me, many thanks!