HMG4 release method

Moderator: Rathinagiri

User avatar
concentra
Posts: 256
Joined: Fri Nov 26, 2010 11:31 am
Location: Piracicaba - Brasil

Re: HMG4 release method

Post by concentra » Wed Aug 03, 2011 11:58 am

Hi All.
I found a problem on releasing recursively all controls of a window.
On a input data form, after the window is released I may need to inspect the window inner controls to process the inputted data.
Sample:

Code: Select all

#include "hmg.ch"
#include "hbqtgui.ch"

FUNCTION Main()

   LOCAL oBtn_Cancel
   LOCAL oBtn_Ok
   LOCAL oButtonBox
   LOCAL oText
   LOCAL oWindow
   LOCAL lOk := .F.

   HbQt_ErrorSys()

   DEFINE WINDOW oWindow Width 200 Height 200
      Type   WND_MAIN

      DEFINE EditBox oText
         ROW    50
         Value     "EditBox Text"
      END TEXTBOX

      DEFINE BUTTONBOX oButtonBox
         ADD BUTTON oBtn_Ok     ROLE BUTTON_OK     ACTION ( lOk := .T., oWindow:Release() )
         ADD BUTTON oBtn_Cancel ROLE BUTTON_CANCEL ACTION oWindow:Release()
      END BUTTONBOX

   END WINDOW

   // Before window release
   MsgInfo( TRIM( oText.Value ) )

   ACTIVATE WINDOW oWindow

   IF lOk

      // Process data contained in an inner control
      // After window release
      MsgInfo( TRIM( oText.Value ) )

   ENDIF

RETURN NIL
After inputting data the operator press OK button and OK button closes the window ( release ).
After the window is closed ( released ) the inputted data must be processed, but the inner control itself was also released...
This approach is very common in my systems.
[[]] Mauricio Ventura Faria

mrduck
Posts: 497
Joined: Fri Sep 10, 2010 5:22 pm

Post by mrduck » Wed Aug 03, 2011 12:50 pm

Unfortunately I could not follow all the messages about windows release but I was asking why there was the need to DELETE the window from the system. And I was surprised hearing about auto-destruction on release()...

anyway, I think that windows should never auto-destroy except when the programmer explicitely request it.

We may have different programming styles. I would adopt the load/create window, put data into widgets, activate the window, when window closes, read the values from the widgets. Others may prefer to put data into the widgets in the onInit method and read data back in the onRelease...


concentra wrote:

Code: Select all

         ADD BUTTON oBtn_Ok     ROLE BUTTON_OK     ACTION ( lOk := .T., oWindow:Release() )
....

   ACTIVATE WINDOW oWindow

   IF lOk
....
It would be possible to avoid the use of variable lOk if we return a meaningful value from window():activate() that now returns NIL. Or otherwise create new methods/data inside the window object to store some infos on how the windows was closed...

User avatar
l3whmg
Posts: 694
Joined: Mon Feb 23, 2009 8:46 pm
Location: Italy
Contact:

Post by l3whmg » Wed Aug 03, 2011 2:24 pm

Hi, I'm in agreement with MrDuck, but ... 1) you can put something within bOnRelease method and 2) in a MDI program I think it's better to Hide not to Release.

When you have a function that show a form, you can create ( the first time ), fill with some data, do something and leave (with hide). The second time you must only fill with new data and show. At the end you can RELEASE ALL WINDOW.

This is my little opinion.

Cheers

p.s. as MrDuck write there are different pow to write
Luigi from Italy
www.L3W.it

Post Reply