On Wed, Jun 15, 2011 at 10:54 AM,  <[email protected]> wrote:

> Just one thought to do with structure/granularity. There are six or so
> methods in your (elegant) solution. But I'd like to have numeric checking on
> entry fields in a number of dialogs, and would prefer not to copy/paste
> code. Arguably the numeric-check methods would be better placed in a
> subclass of the edit control.
>
> So: Is there any way I can subclass the Edit control? Or provide a mixin for
> it? I can't immediately see how this could be done.

There is no easy, effective, way to subclass one of the dialog
controls.  Each dialog control object is actually a singleton object.
The only way to get, let's say, an .Edit object is through the
newEdit() method.  This will always return an .Edit object, not your
subclass.

But it is relatively easy to use a mixin class with a dialog control.
Here is an example:

/**
 *  Simple Dialog showing how to add a
 *  a mixin class to the .Edit class and
 *  use it in a program.
 */

  .Edit~inherit(.ExtraEdit)

  dlg = .SimpleDialog~new
  dlg~execute("SHOWTOP", IDI_DLG_OOREXX)

::requires "ooDialog.cls"

::class 'ExtraEdit' public mixinclass object

::method message
  use strict arg msg = "Message from the Edit control"
  discard = MessageDialog(msg, self~oDlg~dlgHandle,        -
                          "Edit Control")

::method delete
  self~message("I'm deleting my own text")
  self~setText("")

::method addSomeText
  use strict arg text
  self~setText(text)

::class 'SimpleDialog' subclass UserDialog

::method init
  forward class (super) continue

  self~create(30, 30, 257, 123, "Simple Dialog", "CENTER")

::method defineDialog

  self~createEdit(27, 10, 10, 100, 10, "AUTOSCROLLH")
  self~createPushButton(50, 10, 99, 50, 14, , "Push Me",   -
                        onPush)

  self~createPushButton(IDOK, 142, 99, 50, 14, "DEFAULT",  -
                        "Ok")

  self~createPushButton(IDCANCEL, 197, 99, 50, 14, ,       -
                        "Cancel")

::method initDialog
  expose counter edit

        edit = self~newEdit(27)
  edit~setText("Push the button")
  counter = 0

::method onPush unguarded
  expose counter edit

  select
    when counter == 0 then do
      counter += 1
      edit~message
    end
    when counter == 1 then do
      counter += 1
      edit~delete
    end
    when counter == 2 then do
      counter = 0
      edit~addSomeText("Please push me some more.")
    end
  end
  -- End select

::method initAutoDetection
  self~noAutoDetection

There are probably some other techniques that would work, but this is
the easist that comes to mind.

For dialog objects, I have added 2 methods:  addNewMethod() and
addNewAttribute() which allow you add methods and  attributes to a
dialog object.  It would be easy enough to add them to a dialog
control also.

--
Mark Miesfeld

------------------------------------------------------------------------------
EditLive Enterprise is the world's most technically advanced content
authoring tool. Experience the power of Track Changes, Inline Image
Editing and ensure content is compliant with Accessibility Checking.
http://p.sf.net/sfu/ephox-dev2dev
_______________________________________________
Oorexx-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/oorexx-users

Reply via email to