setImageList returns .NIL object

Help
2012-08-30
2012-08-30
  • Staffan Tylen
    Staffan Tylen
    2012-08-30

    Playing around with dialogs I can't figure out why the setImageList method at the end of the program below returns a .NIL object. Despite this the dialog displays OK. (The image is from the ooRexx samples and I'm running ooDialog 4.2.0.)

    mylistview = .Listview~new
    mylistview~execute("SHOWTOP")
    return

    ::requires "oodialog.cls"

    ::class Listview subclass UserDialog
    ::attribute lv private

    ::method init
    expose imagelist
    forward class(super) continue
    imagelist=.ImageList~create(.Size~new(64, 64), .Image~toID(ILC_COLOR4), 1, 0)
    image = .Image~getImage("custlist.bmp", .Image~toID(IMAGE_BITMAP))
    imagelist~add(image)
    image~release
    self~createCenter(300, 300, "My window-title")

    ::method defineDialog
    self~createListView(555, 10, 10, 280, 270, "ICON")

    ::method initDialog
    expose imagelist
    forward class(super) continue
    self~lv = self~newListView(555)
    say self~lv~setImageList(imagelist)
    self~lv~addRow( , 0, "Record 1")

     
    • Mark Miesfeld
      Mark Miesfeld
      2012-08-30

      On Thu, Aug 30, 2012 at 5:45 AM, Staffan Tylen st2430@users.sf.net wrote:

      Playing around with dialogs I can't figure out why the setImageList method at the end of the program below returns a .NIL object. Despite this the dialog displays OK. (The image is from the ooRexx samples and I'm running ooDialog 4.2.0.)

      The answer can be found in the excellent ooDialog documentation for
      the setImageList method:

      Return value:
      The existing image list is returned, if there is one. Otherwise, .nil
      is returned.

      Since there was no previous image list set, the method returns .nil.

      You should read that section in the doc to get an idea about your
      responsibility to release the system resources tied up in a image
      list. When you assign an image list to the list-view, the list-view
      will either handle releasing the image list for you, or not. This
      depends on the list-view style.

      If you remove the current image list from the list-view by assigning
      it a new one, then it becomes your responsibility to release the old
      image list, if you want to. If you were going to use the old image
      list somewhere else, then of course you wouldn't want to release it.

      This is why the old image list, if there is one, is returned to you.

      --
      Mark Miesfeld

       
  • Staffan Tylen
    Staffan Tylen
    2012-08-30

    Thanks Mark. Learning how to read is more difficult then programming! I completely missed the word 'existing'. I will review the doc as you have suggested. Thanks again.

    Staffan

     
    • Mark Miesfeld
      Mark Miesfeld
      2012-08-30

      On Thu, Aug 30, 2012 at 7:10 AM, Staffan Tylen st2430@users.sf.net wrote:

      Thanks Mark. Learning how to read is more difficult then programming! I completely missed the word 'existing'. I will review the doc as you have suggested. Thanks again.

      One word about releasing the image list.

      You do not need to be overly worried about this. When the Rexx
      interpreter process ends, all system resource are released. So, if
      you have a typical program that puts up a dialog, the dialog is
      closed, the program ends. It makes no difference if you release the
      image list(s) used in the dialog. The resources are released
      automatically by the OS.

      The only time you need to think about this is if you have a Rexx
      program that runs for a very long time, and in that program you create
      dialogs, use image lists, close the dialog, over and over again. In
      this case the unreleased image lists would slowly increase memory
      usage in the program. But, even here, the amount of memory is not
      going to be a lot. Just something to think about.

      --
      Mark Miesfeld