Question about the Onshow Event for Dialog

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
sarver311
Pro Scripter
Posts: 84
Joined: Tue Jun 17, 2008 6:37 pm

Question about the Onshow Event for Dialog

Post by sarver311 » Tue Aug 24, 2010 4:00 pm

I have a dialog which is modal and I wanted to make a subroutine run AFTER the dialog is created and shown. I am using the onshow event which works but not as I expected it to. The "dialogsubroutine" runs and THEN the dialog opens and I need it to run after the dialog opens.

I can work around it and use the paint event or do something else to fit my needs but I was just curious if this was normal.

Here is an example script of what I'm talking about.

Code: Select all

Dialog>Dialog1
object Dialog1: TForm
  Left = 285
  Top = 118
  HelpContext = 5000
  BorderIcons = [biSystemMenu]
  Caption = 'CustomDialog'
  ClientHeight = 212
  ClientWidth = 431
  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 = 64
    Top = 56
    Width = 106
    Height = 13
    Caption = 'Here is my Test Dialog'
  end
end
EndDialog>Dialog1

AddDialogHandler>Dialog1,,Onshow,PostShowSub

show>Dialog1,r

srt>PostShowSub
messagemodal> The Sub Ran Successfully.
END>PostShowSub

Thanks

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

Post by Marcus Tettmar » Tue Aug 24, 2010 4:30 pm

THis is correct, because the sub is activated WHILE the dialog is showING. So it appears to you before the dialog is fully visible.

You could use OnActivate with a counter:

Code: Select all

Dialog>Dialog1
object Dialog1: TForm
  Left = 285
  Top = 118
  HelpContext = 5000
  BorderIcons = [biSystemMenu]
  Caption = 'CustomDialog'
  ClientHeight = 212
  ClientWidth = 431
  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 = 64
    Top = 56
    Width = 106
    Height = 13
    Caption = 'Here is my Test Dialog'
  end
end
EndDialog>Dialog1

Let>dlgActive=0
AddDialogHandler>Dialog1,,OnActivate,PostShowSub

show>Dialog1,r

srt>PostShowSub
 If>dlgActive=0
   messagemodal> The Sub Ran Successfully.
 Endif
 Let>dlgActive=dlgActive+1
END>PostShowSub
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

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

sarver311
Pro Scripter
Posts: 84
Joined: Tue Jun 17, 2008 6:37 pm

Post by sarver311 » Tue Aug 24, 2010 4:38 pm

Awesome this is exactly what I needed. Thanks for clarifying things and providing such a simple workaround.

-Josh

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