Different behaviour between Compiled macro vs native script

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
Dominic_Fichera
Pro Scripter
Posts: 82
Joined: Mon Mar 24, 2014 12:15 pm

Different behaviour between Compiled macro vs native script

Post by Dominic_Fichera » Fri Sep 12, 2014 8:33 am

Hey guys,

I'm having an issue with a script I've created. When I run it through Macro scheduler, I have no problems. Once I compile it, the script starts acting weird.

I've recorded a video of the odd behaviour and am hoping someone might be able to pinpoint the issue.
https://www.dropbox.com/s/n9qnq4evppjuc ... r.mp4?dl=0


As I mentioned in the video, at about 15 seconds, when I click "login" with the incorrect password, the dialog disappears and gives an "incorrect password" error. This is what I want to happen. At about 21 seconds, I do the same thing with the compiled version which DOESN'T close the dialog. This is where I believe the error is coming from. Any suggestions on how I can ensure the dialog is closed? I've tried adding the code in a few times just as a failsafe, but it still doesn't work. I am thinking maybe it is a glitch with the compiler. I'm not too sure.

If you need anymore information, or if I have confused you more, please feel free to ask :). Also, if you require the code, here is a link to a stripper down version of it that has the same issue when compiled: https://www.dropbox.com/s/ycaum548jfz9m ... r.scp?dl=0

Thanks in advance :)

Dominic Fichera

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

Re: Different behaviour between Compiled macro vs native scr

Post by JRL » Fri Sep 12, 2014 2:33 pm

Here's a workable copy of your script. I removed your image and other lines from the dialog for brevity. and added a "doCloseMainMenu" subroutine to make it self contained.

In my opinion you need to be using a non-modal dialog. Modal dialogs are designed to display permanently. Non-modal dialogs can be turned on and off at will.

I can't explain why Closedialog> works from a script when you have a modal dialog. In my opinion it should not. From a modal dialog, you can only process subroutines. When the subroutine completes, the script returns to the dialog. If the dialog is closed, the user has no way to continue and the script is left hanging.

If you need to use a modal dialog, then I suggest controlling its visibility by using SetDialogProperty>DialogName,,Visible,False and SetDialogProperty>DialogName,,Visible,True.

Code: Select all

Dialog>Login
object Login: TForm
  BorderIcons = []
  BorderStyle = bsSingle
  Caption = 'Fichera Yard Maintenance - Login'
  ClientHeight = 113
  ClientWidth = 281
  object Label1: TLabel
    Left = 120
    Top = 16
    Width = 137
    Height = 13
    Caption = 'Please Enter Your Password:'
  end
  object LoginPass: TEdit
    Left = 120
    Top = 32
    Width = 153
    Height = 21
    PasswordChar = '*'
    TabOrder = 0
  end
  object Login: tMSButton
    Left = 120
    Top = 64
    Width = 75
    Height = 25
    Caption = 'Login'
    Default = True
  end
  object Close: tMSButton
    Left = 200
    Top = 64
    Width = 75
    Height = 25
    Caption = 'Close'
  end
end
EndDialog>Login
Label>login

Let>cleanPassword=password
AddDialogHandler>Login,Login,onClick,doLogin
AddDialogHandler>Login,Close,onClick,doCloseMainMenu
SetDialogProperty>Login,LoginPass,text,
Show>Login

Label>IdleLoop
  Wait>0.01
  If>varPassword=cleanPassword
    Goto>Continue
  EndIf
Goto>IdleLoop

SRT>doLogin
    GetDialogProperty>Login,LoginPass,text,varPassword
    CloseDialog>Login
  If>varPassword<>cleanPassword
    MessageModal>Password incorrect. Please try again.
    SetDialogProperty>Login,LoginPass,text,
    SetDialogObjectFocus>Login,LoginPass
    Show>Login
  EndIf
END>doLogin

SRT>doCloseMainMenu
  Exit>0
END>doCloseMainMenu

Label>Continue
//login successful - continue
CloseDialog>Login

MessageModal>Main Menu

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Re: Different behaviour between Compiled macro vs native scr

Post by Marcus Tettmar » Sun Sep 14, 2014 6:59 am

>> I can't explain why Closedialog> works from a script when you have a modal dialog. <<

When running in the editor you are in the DEBUGGER. In this state modality of dialogs is SIMULATED - they're not fully modal. Because if they were you would not be able to debug. This may explain why CloseDialog works in this state, and may explain subtle differences between running from within the editor versus outside the editor or in a .exe.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

Dominic_Fichera
Pro Scripter
Posts: 82
Joined: Mon Mar 24, 2014 12:15 pm

Re: Different behaviour between Compiled macro vs native scr

Post by Dominic_Fichera » Mon Sep 15, 2014 8:49 am

Thanks everyone for your help with this one :) With JRLs changes, I have been able to get the macro working.

I never did get the hang of non-modal dialogs, but hopefully with a bit more practice with this example I should be right :)

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