class: their use

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

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

class: their use

Post by l3whmg »

I guys,
I'm trying to understand class and their use (I look at HMG4 for example). For this reason I write a simple program that "simulate" some concept in HMG4; work fine if I add objects but fails when I remove.
After "oWindows:DelForm( "form1" )" (and "form3" adding) the object "form2" change it's property "title" from "title form2" to "title form3". I don't know why.

Is there someone can help me? Many thanks in advance.

This is the source

Code: Select all

#include "hmg.ch"
#include "hbclass.ch"

MEMVAR oWindows

FUNCTION main()
 
 PUBLIC oWindows := LW_MAIN():New()

 p000_FrmDefine()

RETURN NIL

*..................................................................................
* definizione main form
*..................................................................................
STATIC FUNCTION p000_FrmDefine()

 DEFINE WINDOW p000win ;
  ROW 0 ;
  COL 0 ;
  WIDTH 860 ;
  HEIGHT 645 ;
  WINDOWTYPE MAIN ;
  TITLE "Main form" ;
  ON INIT p000_OnInit() ;
  FONTNAME "Arial" FONTSIZE 10

  DEFINE MAIN MENU
   DEFINE POPUP '&File'
    MENUITEM 'e&Xit' ACTION p000_Exit()
   END POPUP
   DEFINE POPUP '&Test'
    MENUITEM '&2 Call' ACTION p000_Call2()
   END POPUP
  END MENU

 END WINDOW

 p000win.Activate()

RETURN NIL

*..................................................................................
* OnInit
*..................................................................................
STATIC FUNCTION p000_OnInit()

 p000win.Center()

RETURN NIL

*..................................................................................
* exit
*..................................................................................
STATIC FUNCTION p000_Exit()

  p000win.Release()

RETURN NIL

*..................................................................................
* Call
*..................................................................................
STATIC FUNCTION p000_Call2()

 MSGSTOP( "oWindows:FormList " + HB_VALTOEXP( oWindows:FormList ) )

* form1
 WITH OBJECT LW_WIN():New()
  :Name  := "form1"
  :Title := "title form1"
  :Create()
 END WITH

 MSGSTOP( "oWindows:FormList " + HB_VALTOEXP( oWindows:FormList ) )
 MSGSTOP( "oWindows:form1:title " + HB_VALTOEXP( oWindows:form1:title ) )

* form2
 WITH OBJECT LW_WIN():New()
  :Name  := "form2"
  :Title := "title form2"
  :Create()
 END WITH

 MSGSTOP( "oWindows:FormList " + HB_VALTOEXP( oWindows:FormList ) )
 MSGSTOP( "oWindows:form2:title " + HB_VALTOEXP( oWindows:form2:title ) )
 MSGSTOP( "oWindows:form1:title " + HB_VALTOEXP( oWindows:form1:title ) )

 oWindows:DelForm( "form1" )

* form3
 WITH OBJECT LW_WIN():New()
  :Name  := "form3"
  :Title := "title form3"
  :Create()
 END WITH

 MSGSTOP( "oWindows:FormList " + HB_VALTOEXP( oWindows:FormList ) )
 MSGSTOP( "oWindows:form3:title " + HB_VALTOEXP( oWindows:form3:title ) )
 MSGSTOP( "oWindows:form2:title " + HB_VALTOEXP( oWindows:form2:title ) )

RETURN NIL

*==================================================================================
* class LW_MAIN
*==================================================================================
CLASS LW_MAIN

* shared values
 CLASS VAR oMainDefParent       INIT   NIL      SHARED

* internal data
 DATA aObjAdded                 INIT   {}       PROTECTED

* methods
 METHOD New
 METHOD AddForm
 METHOD DelForm
 METHOD FormCount               INLINE LEN( ::aObjAdded )
 METHOD FormList                INLINE ::aObjAdded

* properties

ENDCLASS

*------------------------------------------------------------------------------*
* class LW_MAIN Methods
*------------------------------------------------------------------------------*

*..............................................................................*
* class LW_MAIN - New method
*..............................................................................*
METHOD LW_MAIN:New()

 ::oMainDefParent := Self

RETURN Self

*..............................................................................*
* class LW_WIN - AddForm method
*..............................................................................*
METHOD LW_MAIN:AddForm( cName, oObject )

 LOCAL lAdded := .F.
 LOCAL nPos := ASCAN( ::aObjAdded, cName )
 
 IF !__objHasMsg( Self, cName ) .AND. !__objHasMsg( Self, "_" + cName ) .AND. nPos == 0
  __objAddData( Self , cName )
  AADD( ::aObjAdded, cName )
  ::&cName := oObject
  lAdded := .T.
 ENDIF

RETURN lAdded

*..............................................................................*
* class LW_WIN - DelForm method
*..............................................................................*
METHOD LW_MAIN:DelForm( cName )

 LOCAL nPos := ASCAN( ::aObjAdded, cName )
 
 IF nPos > 0
  __objDelData( Self , cName )
  ::aObjAdded := HB_ADEL( ::aObjAdded, nPos, .T. )
 ENDIF

RETURN NIL

*------------------------------------------------------------------------------*
* class LW_MAIN Properties
*------------------------------------------------------------------------------*

*==================================================================================
* class LW_WIN
*==================================================================================
CLASS LW_WIN FROM LW_MAIN

* shared values

* internal data
 DATA oParent                   INIT   NIL      PROTECTED
 DATA cName                     INIT   ""       PROTECTED
 DATA cTitle                    INIT   ""       PROTECTED

* Methods
 METHOD New
 METHOD Create

* properties
 METHOD Name                    SETGET
 METHOD Title                   SETGET

ENDCLASS

*------------------------------------------------------------------------------*
* class LW_WIN Methods
*------------------------------------------------------------------------------*

*..............................................................................*
* class LW_WIN - New method
*..............................................................................*
METHOD LW_WIN:New()

 ::oParent := ::oMainDefParent

RETURN Self

*..............................................................................*
* class LW_WIN - Create method
*..............................................................................*
METHOD LW_WIN:Create()

 IF ::oParent:AddForm( ::cName, Self ) == .F.
  MSGSTOP( ::cName + "Already Exist" )
 ENDIF

RETURN NIL

*------------------------------------------------------------------------------*
* class LW_WIN Properties
*------------------------------------------------------------------------------*

*..............................................................................*
* class LW_WIN - Name property
*..............................................................................*
METHOD LW_WIN:Name( cArg1 )

 IF PCOUNT() == 0
  RETURN ::cName
 ELSEIF HB_ISCHAR( cArg1 )
  ::cName := cArg1
 ENDIF
 
RETURN NIL
*..............................................................................*
* class LW_WIN - Title property
*..............................................................................*
METHOD LW_WIN:Title( cArg1 )

 IF PCOUNT() == 0
  RETURN ::cTitle
 ELSEIF HB_ISCHAR( cArg1 )
  ::cTitle := cArg1
 ENDIF
 
RETURN NIL
Luigi from Italy
www.L3W.it
User avatar
l3whmg
Posts: 694
Joined: Mon Feb 23, 2009 8:46 pm
Location: Italy
Contact:

Re: class: their use

Post by l3whmg »

Hi, I found solution by myself :)
Instead of using the statement "__objDelData" is sufficient to assign the value "NIL" to the object; therefore, I can use a syntax like this: "Self:&cName := NIL".
Any way, use of "__objDelData" in my source, it's my mistake or it's Harbour problem?

Best regard.
Luigi from Italy
www.L3W.it
User avatar
l3whmg
Posts: 694
Joined: Mon Feb 23, 2009 8:46 pm
Location: Italy
Contact:

Re: class: their use

Post by l3whmg »

Hi guys. Well,I've done an exercise with class; I'm inspired by HMG.
I leave these sources for other newbe like me or, perhaps, for give some idea to someone; but remember: it's an exercise.

Best regards and Happy New Year
Attachments
Classes.zip
example for HMG3
(2.88 KiB) Downloaded 199 times
Luigi from Italy
www.L3W.it
User avatar
Rathinagiri
Posts: 5471
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Contact:

Re: class: their use

Post by Rathinagiri »

Thanks a lot Luigi. Surely helpful to me.
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
User avatar
danielmaximiliano
Posts: 2607
Joined: Fri Apr 09, 2010 4:53 pm
Location: Argentina
Contact:

Re: class: their use

Post by danielmaximiliano »

l3whmg wrote:Hi guys. Well,I've done an exercise with class; I'm inspired by HMG.
I leave these sources for other newbe like me or, perhaps, for give some idea to someone; but remember: it's an exercise.

Best regards and Happy New Year
Hola Luigui :
ya pasaron casi 2 años desde que publico este ejercicio.
nunca trabaje con clases en Harbour pero Pascal tiene casi la misma forma de manejo; espero aprender bien a manejarlos.
gracias por compartir como siempre su conocimiento.

Hello Luigui:
It's been nearly two years since he published this sample.
Never work with classes at Harbour but Pascal has almost the same form of management, I hope to learn to handle them well.
as always thanks for sharing your knowledge.
*´¨)
¸.·´¸.·*´¨) ¸.·*¨)
(¸.·´. (¸.·` *
.·`. Harbour/HMG : It's magic !
(¸.·``··*

Saludos / Regards
DaNiElMaXiMiLiAnO

Whatsapp. := +54901169026142
Telegram Name := DaNiElMaXiMiLiAnO
Post Reply