On Sun, Oct 13, 2013 at 6:17 PM, <artstore@artheimsoth.com> wrote:
How would I go about passing a parm to an oodialog program from the
command line in Windows?  Example:
  rexx mytest.rex parm1 parm2

Hi Art,

Break it into 2 parts.  

The first part is passing the args into the Rexx program.  You may already know this, but since you asked, I'm going to assume you don't.  The command line arguments are passed into the Rexx program as a single string.  Then it is just a matter of parsing the string into the arguments.

The parsing is fairly straight forward, but you can make it somewhat complicated if you have a lot of error checking you want to do.  For your own program that you are fairly show the arguments will likely be correct, I would do something like:

/* somePrg.rex */
use arg cmdLine

  if cmdLine~words <> 2 then do
    say 'Syntax: somePrg param1 param2'
    return 99
  end
  
  param1 = cmdLine~word(1)  
  param2 = cmdLine~word(2)

I've been accused of not being very "Rexxish," mostly because I'm not.  Most Rexx programmers would probably use parse to break the command line arguments down.

Then in InitDialog or a later method, I would like to retrieve the
value(s) of the initiation parameters.  Possible?

There are two approaches to passing the arguments on to the dialog subclass.  You can add the arguments to the new() invocation for the dialog, or you could add an attribute to your dialog subclass and set them to the value(s) of the imitation parameters.

If you pass them in as extra arguments to the new() method, you need to take care to initialize the super class with the correct arguments.  For instance you can't just forward the message in init() to the super class, because the super class doesn't know about those extra arguments.  For instance:

  dlg = .SimpleRcDlg~new("simple.rc", IDD_SIMPLE_DLG, , "simple.h", param1, param2)
  dlg~execute("SHOWTOP", IDI_DLG_OOREXX)
...

::class 'SimpleRcDlg' subclass RcDialog

::method init
  use arg rcFile, id, dlgData., hFile, param1, param2

  forward class (super) continue

will give you:

     3 *-* dlg = .SimpleRcDlg~new("simple.rc", IDD_SIMPLE_DLG, , "simple.h", param1, param2)
Error 88 running C:\work.ooRexx\other\feature.requests\rcDlg.rex line 3:  Invalid argument
Error 88.905:  Argument 10 must be a positive whole number; found "PARAM2" 

You need to do something like this:

::class 'SimpleRcDlg' subclass RcDialog

::method init
  expose param1 param2
  use arg rcFile, id, dlgData., hFile, param1, param2

  self~init:super(rcFile, id, , hFile)

And, this can have further complications, if, say sometimes you want to use the third arg and sometimes you don't.  

I usually take the second approach and would do something like this:


/* Simple RcDialog template */
use arg cmdLine

  if cmdLine~words <> 2 then do
    say 'Syntax: somePrg param1 param2'
    return 99
  end

  param1 = cmdLine~word(1)
  param2 = cmdLine~word(2)

  dlg = .SimpleRcDlg~new("simple.rc", IDD_SIMPLE_DLG, , "simple.h")
  dlg~setArgs(param1, param2)
  
  dlg~execute("SHOWTOP", IDI_DLG_OOREXX)

return 0
-- End of entry point.

/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*\
  Directives, Classes, or Routines.
\* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
::requires "ooDialog.cls"

::class 'SimpleRcDlg' subclass RcDialog

::attribute param1
::attribute param2

::method init
  use arg rcFile, id, dlgData., hFile, param1, param2

  self~init:super(rcFile, id, , hFile)

::method setArgs
  use strict arg p1, p2
  self~param1 = p1
  self~parma2 = p2
  
::method initDialog

  if self~param1 == 'cat' then do
    -- do something
  end
  
  -- use param2 for something ...  

Well, I was just finishing this up when I saw you second post, so I might as well send it.

--
Mark Miesfeld