Items in 2nd Combo being Constructed on the fly

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
armsys
Automation Wizard
Posts: 1108
Joined: Wed Dec 04, 2002 10:28 am
Location: Hong Kong

Items in 2nd Combo being Constructed on the fly

Post by armsys » Mon Jan 24, 2011 10:12 pm

In the following script, two combos are displayed when lists in combo2 are changed depending upon the selection of the items in combo1. So far my code fails. Please help. Thanks.

Code: Select all

Dialog>Dialog1
object Dialog1: TForm
  Left = 690
  Top = 127
  HelpContext = 5000
  BorderIcons = [biSystemMenu]
  BorderWidth = 2
  Caption = 'Double Combos'
  ClientHeight = 208
  ClientWidth = 427
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = True
  Position = poDesktopCenter
  ShowHint = True
  OnTaskBar = False
  PixelsPerInch = 96
  TextHeight = 13
  object Label1: TLabel
    Left = 24
    Top = 38
    Width = 42
    Height = 13
    Caption = 'Category'
  end
  object Label2: TLabel
    Left = 232
    Top = 38
    Width = 20
    Height = 13
    Caption = 'Item'
  end

  object msComboBox1: tMSComboBox
    Left = 73
    Top = 36
    Width = 145
    Height = 21
    Style = csDropDownList
    ItemHeight = 13
    ItemIndex = 0
    TabOrder = 0
    Text = 'Cat 1'
    Items.Strings = (
      'Cat 1'
      'Cat 2'
      'Cat 3'
      'Cat 4'
      'Cat 5')
    ListText = 'Cat 1'#13#10'Cat 2'#13#10'Cat 3'#13#10'Cat 4'#13#10'Cat 5'#13#10
  end
  object MSComboBox2: tMSComboBox
    Left = 254
    Top = 38
    Width = 145
    Height = 21
    Style = csDropDownList
    ItemHeight = 13
    ItemIndex = 0
    TabOrder = 2
    Text = 'Item 1'
    Items.Strings = (
      'Item 1'
      'Item 2'
      'Item 3')
    ListText = 'Item 1'#13#10'Item 2'#13#10'Item 3'#13#10
  end
end
EndDialog>Dialog1
Let>List2=Itemx 1'#13#10'Itemx 2'#13#10'Itemx 3'#13#10
  MDL>I am OKAY
AddDialogHandler>Dialog1,MSComoBox1,OnClick,DoChgList
Show>Dialog1,ModalResult
SRT>DoChgList
  MDL>I am OKAY
  GetDialogObjectProperty>Dialog1,MSComboBox1,ItemIndex,num
  MessageModal>num
  If>num=1
    Let>List=Itemx 1'#13#10'Itemx 2'#13#10'Itemx 3'#13#10
    SetDialog1,MSComboBox2,ListText,List
    SetDialogObjectFocus>Dialog1,MSComboBox2
  Endif
End>DoChgList

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

Post by JRL » Mon Jan 24, 2011 11:04 pm

Changes are below remarked lines from your code. Hope this is what you were looking for.

Code: Select all

Dialog>Dialog1
object Dialog1: TForm
  Left = 690
  Top = 127
  HelpContext = 5000
  BorderIcons = [biSystemMenu]
  BorderWidth = 2
  Caption = 'Double Combos'
  ClientHeight = 208
  ClientWidth = 427
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = True
  Position = poDesktopCenter
  ShowHint = True
  OnTaskBar = False
  PixelsPerInch = 96
  TextHeight = 13
  object Label1: TLabel
    Left = 24
    Top = 38
    Width = 42
    Height = 13
    Caption = 'Category'
  end
  object Label2: TLabel
    Left = 232
    Top = 38
    Width = 20
    Height = 13
    Caption = 'Item'
  end

  object msComboBox1: tMSComboBox
    Left = 73
    Top = 36
    Width = 145
    Height = 21
    Style = csDropDownList
    ItemHeight = 13
    ItemIndex = 0
    TabOrder = 0
    Text = 'Cat 1'
    Items.Strings = (
      'Cat 1'
      'Cat 2'
      'Cat 3'
      'Cat 4'
      'Cat 5')
    ListText = 'Cat 1'#13#10'Cat 2'#13#10'Cat 3'#13#10'Cat 4'#13#10'Cat 5'#13#10
  end
  object MSComboBox2: tMSComboBox
    Left = 254
    Top = 38
    Width = 145
    Height = 21
    Style = csDropDownList
    ItemHeight = 13
    ItemIndex = 0
    TabOrder = 2
    Text = 'Item 1'
    Items.Strings = (
      'Item 1'
      'Item 2'
      'Item 3')
    ListText = 'Item 1'#13#10'Item 2'#13#10'Item 3'#13#10
  end
end
EndDialog>Dialog1
Let>List2=Itemx 1'#13#10'Itemx 2'#13#10'Itemx 3'#13#10
 //MDL>I am OKAY
//AddDialogHandler>Dialog1,MSComoBox1,OnClick,DoChgList
AddDialogHandler>Dialog1,MSComboBox1,OnClick,DoChgList
GetDialogProperty>Dialog1,MSComboBox2,ListText,test
Show>Dialog1,ModalResult
SRT>DoChgList
  //MDL>I am OKAY
  //GetDialogObjectProperty>Dialog1,MSComboBox1,ItemIndex,num
  GetDialogProperty>Dialog1,MSComboBox1,ItemIndex,num
  //MessageModal>num
  If>num=1
    //Let>List=Itemx 1'#13#10'Itemx 2'#13#10'Itemx 3'#13#10
    Let>List=Itemx 1%CRLF%Itemx 2%CRLF%Itemx 3%CRLF%
    //SetDialog1,MSComboBox2,ListText,List
    SetDialogProperty>Dialog1,MSComboBox2,ListText,List
    SetDialogProperty>Dialog1,MSComboBox2,ItemIndex,0
    SetDialogObjectFocus>Dialog1,MSComboBox2
  Endif
End>DoChgList

armsys
Automation Wizard
Posts: 1108
Joined: Wed Dec 04, 2002 10:28 am
Location: Hong Kong

Post by armsys » Tue Jan 25, 2011 4:17 am

Hi JRL
Thanks for your help. The following is the fully working script demonstrating the on-the-fly changes in the 2nd Combo triggered by the selection in the 1st combo.
Thank you.

Code: Select all

Let>List0=Item1 1%CRLF%Item1 2%CRLF%Item1 3%CRLF%
Let>List1=Item2 1%CRLF%Item2 2%CRLF%Item2 3%CRLF%
Let>List2=Item3 1%CRLF%Item3 2%CRLF%Item3 3%CRLF%
Let>List3=Item4 1%CRLF%Item4 2%CRLF%Item4 3%CRLF%
Let>List4=Item5 1%CRLF%Item5 2%CRLF%Item5 3%CRLF%

Dialog>Dialog1
object Dialog1: TForm
  Left = 690
  Top = 127
  HelpContext = 5000
  BorderIcons = [biSystemMenu]
  BorderWidth = 2
  Caption = 'Double Combos'
  ClientHeight = 208
  ClientWidth = 427
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = True
  Position = poDesktopCenter
  ShowHint = True
  OnTaskBar = False
  PixelsPerInch = 96
  TextHeight = 13
  object Label1: TLabel
    Left = 24
    Top = 38
    Width = 42
    Height = 13
    Caption = 'Category'
  end
  object Label2: TLabel
    Left = 232
    Top = 38
    Width = 20
    Height = 13
    Caption = 'Item'
  end

  object msComboBox1: tMSComboBox
    Left = 73
    Top = 36
    Width = 145
    Height = 21
    Style = csDropDownList
    ItemHeight = 13
    ItemIndex = 0
    TabOrder = 0
    Text = 'Cat 1'
    Items.Strings = (
      'Cat 1'
      'Cat 2'
      'Cat 3'
      'Cat 4'
      'Cat 5')
    ListText = 'Cat 1'#13#10'Cat 2'#13#10'Cat 3'#13#10'Cat 4'#13#10'Cat 5'#13#10
  end
  object MSComboBox2: tMSComboBox
    Left = 254
    Top = 38
    Width = 145
    Height = 21
    Style = csDropDownList
    ItemHeight = 13
    ItemIndex = 0
    TabOrder = 2
    Text = 'Item 1'
    Items.Strings = (
      'Item 1'
      'Item 2'
      'Item 3')
       ListText = 'Item1 1'#13#10'Item1 2'#13#10'Item1 3'#13#10
    end
end
EndDialog>Dialog1
AddDialogHandler>Dialog1,MSComboBox1,OnClick,DoChgList
GetDialogProperty>Dialog1,MSComboBox2,ListText,test
Show>Dialog1,ModalResult
SRT>DoChgList
  GetDialogProperty>Dialog1,MSComboBox1,ItemIndex,num
  Let>List=List%num%
  SetDialogProperty>Dialog1,MSComboBox2,ListText,List
  SetDialogProperty>Dialog1,MSComboBox2,ItemIndex,0
  SetDialogObjectFocus>Dialog1,MSComboBox2
End>DoChgList

armsys
Automation Wizard
Posts: 1108
Joined: Wed Dec 04, 2002 10:28 am
Location: Hong Kong

Post by armsys » Tue Jan 25, 2011 4:22 am

In my last post, so far I'm unable to code inside MSComobox2:
ListText = List0
Why?

List0 is already initiated ine the very beginning.
Macro Scheduler demands in the MSCombobox2 it must coded as:
ListText = 'Item1 1'#13#10'Item1 2'#13#10'Item1 3'#13#10

Please help. Thanks in advance.

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 Jan 25, 2011 7:53 am

The ONLY way to set properties at runtime is with SetDialogProperty. With v12 dialogs you cannot put a variable inside the dialog block. So what you have to do is, after the dialog block:

SetDialogProperty>Dialog1,MSComboBox2,ListText,List0

Just remember that for setting properties at runtime always use SetDialogProperty. And to get them: GetDialogProperty. That's it.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

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

armsys
Automation Wizard
Posts: 1108
Joined: Wed Dec 04, 2002 10:28 am
Location: Hong Kong

Post by armsys » Tue Jan 25, 2011 9:05 am

Marcus,
Thanks for your explanation. The caveat here is: Don't mess with code generated by Dialog Designer. After several experiements, I discover SetDialogProperty>Dialog1,MSComboBox2,ListText,List0 (the initial list) should be placed before EndDialog>.
Placing it after EndDailog> doesn't work as expected.

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 Jan 25, 2011 9:19 am

Err, no SetDialogProperty would need to be AFTER EndDialog and should not be inside the dialog block. It would have to be after EndDialog for the dialog it refers to otherwise it refers to a dialog that doesn't exist yet.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

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

armsys
Automation Wizard
Posts: 1108
Joined: Wed Dec 04, 2002 10:28 am
Location: Hong Kong

Post by armsys » Tue Jan 25, 2011 9:46 am

Marcus,
Yes, you're right and I was wrong. Definitively the SetDialogProperty must be placed after Show>. The following code deliberately assigns a different string to the first ListText in the MSComboBox2. The SetDialogProperty changes it on the fly. Thanks for correcting my mistake.

Code: Select all

Let>List0=Macro Scheduler%CRLF%Item1 2%CRLF%Item1 3%CRLF%
Let>List1=Item2 1%CRLF%Item2 2%CRLF%Item2 3%CRLF%
Let>List2=Item3 1%CRLF%Item3 2%CRLF%Item3 3%CRLF%
Let>List3=Item4 1%CRLF%Item4 2%CRLF%Item4 3%CRLF%
Let>List4=Item5 1%CRLF%Item5 2%CRLF%Item5 3%CRLF%

Dialog>Dialog1
object Dialog1: TForm
  Left = 690
  Top = 127
  HelpContext = 5000
  BorderIcons = [biSystemMenu]
  BorderWidth = 2
  Caption = 'Double Combos'
  ClientHeight = 208
  ClientWidth = 427
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = True
  Position = poDesktopCenter
  ShowHint = True
  OnTaskBar = False
  PixelsPerInch = 96
  TextHeight = 13
  object Label1: TLabel
    Left = 24
    Top = 38
    Width = 42
    Height = 13
    Caption = 'Category'
  end
  object Label2: TLabel
    Left = 232
    Top = 38
    Width = 20
    Height = 13
    Caption = 'Item'
  end

  object msComboBox1: tMSComboBox
    Left = 73
    Top = 36
    Width = 145
    Height = 21
    Style = csDropDownList
    ItemHeight = 13
    ItemIndex = 0
    TabOrder = 0
    Text = 'Cat 1'
    Items.Strings = (
      'Cat 1'
      'Cat 2'
      'Cat 3'
      'Cat 4'
      'Cat 5')
    ListText = 'Cat 1'#13#10'Cat 2'#13#10'Cat 3'#13#10'Cat 4'#13#10'Cat 5'#13#10
  end
  object MSComboBox2: tMSComboBox
    Left = 254
    Top = 38
    Width = 145
    Height = 21
    Style = csDropDownList
    ItemHeight = 13
    ItemIndex = 0
    TabOrder = 2
    Text = 'Item 1'
    Items.Strings = (
      'Item 1'
      'Item 2'
      'Item 3')
    ListText = 'Item1 1'#13#10'Item1 2'#13#10'Item1 3'#13#10
  end
end
EndDialog>Dialog1
SetDialogProperty>Dialog1,MSComboBox2,ListText,List0
SetDialogProperty>Dialog1,MSComboBox2,ItemIndex,0

AddDialogHandler>Dialog1,MSComboBox1,OnClick,DoChgList

Show>Dialog1,ModalResult
SRT>DoChgList
  GetDialogProperty>Dialog1,MSComboBox1,ItemIndex,num
  Let>List=List%num%
  SetDialogProperty>Dialog1,MSComboBox2,ListText,List
  SetDialogProperty>Dialog1,MSComboBox2,ItemIndex,0
  SetDialogObjectFocus>Dialog1,MSComboBox2
End>DoChgList

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