On Sun, May 29, 2011 at 12:39 PM,  <[email protected]> wrote:

I'm going to move this one question / point of yours to the top:

> I have the impression that using auto-detect is meant to make things easier
> for the programmer. But I can't see this.

Exactly!  You hit the nail on the head.  This is why I don't like the
whole concept, and don't use it in my programs.

> But I still don't understand it all, even though I've read the sections of
> ooDialog Reference that you pointed out. I've been trying to understand the
> relationship between:
> (a) a control (e.g. an Edit control)
> (b) the data value placed in that control (e.g. the string "ABC123")
> (c) dlgData as in the third param of the following line of code:
>    dlg = .ProductView~new("ProductView.rc", IDD_PRODUCT_VIEW, dlgData.,
> "ProductView.h")
> ...
> I guess the first question is this: am I supposed to be able to use the
> third param directly myself as a programmer? I assumed "yes".

Sort of yes, but it is mostly used internally.  You populate the stem
*before* you pass it to the new() method.  Then *after* the dialog is
closed you can use it to get the values of the controls when the user
closed the dialog with 'ok'.  If the user closed the dialog with
'cancel', the values are meaningless.

> So, I have a
> .h file with an edit control with id 1002. Suppose I want to populate this
> with the data "ABC123"?
> How would I do this?

Here is your program stripped down of everything not needed to show
how to do it.  When you execute the program "ABC123" will be in the
edit control.  If you type something else in the edit control and
close with 'ok' then it will print out whatever text you had typed.

  data.1002 = "ABC123"

  dlg = .RcDlg~new("dlg.rc", IDD_DIALOG1, data., "dlg.h")

  if dlg~execute("SHOWTOP") == 1 then do
    say "Text in edit control on close with 'ok':"
    say data.1002
  end

::REQUIRES "ooDialog.cls"

::CLASS RcDlg SUBCLASS RcDialog PUBLIC

The above is the complete program.  Note that there is no code to set
the edit control text to "ABC123" in the program.  Yet it does get
set.  Here is an execution where I typed 'Mark' in the edit control
then pressed the Ok button:

C:\work>RcDlg.rex
Text in edit control on close with 'ok':
Mark

C:\work>

> I tried in the initDialog method with no success. And also in an event
> handler method (for a pushbutton).
> In both, I did:
>  dlgdata.DATA1002 = "ABC1002"
> In both, the interpreter said dlgData was a string, not a stem variable.

Yeah, you are just on the wrong track completely.  The usage is as I show above.

By the way, this code in your program shows a common misunderstanding
with exposed variables:

::METHOD ok UNGUARDED
  expose dlgData
  say dlgData.DATA1002

The exposed object variable is not in the local .RcDlg variable pool.
It is only in the .PlainBasDialog's variabl pool.  You can not access
it by exposing its name.  This is an ooRexx topic that is confusing,
and I don't want to go into it here.  But, just as an FYI, you could
gain access to it this way:

::METHOD ok UNGUARDED
  s. = self~dlgData
  say s.DATA1002

> One other thing - when the "data attributes" of a dialog are mentioned, it
> doesn't seem to mean the same thing as an attribute (::ATTRIBUTE) of a
> class. Is that right?

No, that is not right.  "Data attributes" are indeed ::attributes.
They are created by the ooDialog framework on the fly within the
dialog object.  A "dialog data stem", is not an attribute.  "Automatic
data detection" is really only the automatic detection of the controls
in a ResDialog, a ResDialog only, no other type of dialog.

However, the internal implementation of these 3 different things is
very tightly woven together.  So much so, that if you turn "automatic
data detection" off, you turn all of it off.  So much so, that you can
not turn off just one of the 3 different things.

There is no easy way to talk about it if you have to mention all 3
things every time you really just want to talk about the whole
interwoven process.  So I usually just use one of the terms when
talking about it in general, data attributes or automatic data
detection.

Here is your example program changed to show the data attribute part of this:

/* RcDlg_2.rex */

  dlg = .RcDlg~new("dlg.rc", IDD_DIALOG1, , "dlg.h")

  dlg~IDC_EDIT1 = "ABC123"

  if dlg~execute("SHOWTOP") == 1 then do
    say "Text in edit control on close with 'ok':"
    say dlg~IDC_EDIT1
  end

::REQUIRES "ooDialog.cls"

::CLASS RcDlg SUBCLASS RcDialog PUBLIC

> Btw, another question is, when I omit the third param (dlgData), how do I
> populate an edit control with its initial data?

You turn automatic data detection off and populate it like you
originally tried to.  Here is an example:

/* RcDlg_1.rex  */

  dlg = .RcDlg~new("dlg.rc", IDD_DIALOG1, , "dlg.h")
  dlg~execute("SHOWTOP")

::REQUIRES "ooDialog.cls"

::CLASS RcDlg SUBCLASS RcDialog PUBLIC

::method 'initDialog'

  self~newEdit(IDC_EDIT1)~setText("ABC123")

::method ok unguarded
  say "Text in edit control on close with 'ok':"
  say self~newEdit(IDC_EDIT1)~getText

  return self~ok:super

::method initAutoDetection
  self~noAutoDetection

Here is the execution when I type Hank in the edit control:

C:\work>RcDlg_1.rex
Text in edit control on close with 'ok':
Hank

The above is the method I would advocate.  In the above, you'll notice
that for a simple program, you can implement the same functionality
with a few less lines of code by using auto detection.  However, it is
harder to understand how the program works.  With a complex program,
it would be much harder for another programmer to understand how it
works.

I personally wish auto detection was off by default, but it isn't.

--
Mark Miesfeld

------------------------------------------------------------------------------
vRanger cuts backup time in half-while increasing security.
With the market-leading solution for virtual backup and recovery, 
you get blazing-fast, flexible, and affordable data protection.
Download your free trial now. 
http://p.sf.net/sfu/quest-d2dcopy1
_______________________________________________
Oorexx-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/oorexx-users

Reply via email to