HMG OOP?... WHY NOT?... ;) [UPDATED]

HMG announcements; Latest HMG-related news, releases, fixes and updates.

Moderator: Rathinagiri

User avatar
Roberto Lopez
HMG Founder
Posts: 3980
Joined: Wed Jul 30, 2008 6:43 pm
Has thanked: 27 times
Been thanked: 168 times

HMG OOP?... WHY NOT?... ;) [UPDATED]

Post by Roberto Lopez » Mon May 03, 2010 12:39 am

The number one question across my eight years dedicated to HMG is: Why HMG is not *True* OOP?

I've answered that question hundred times...

Most OOP implementations at the time that I've started MiniGUI library, were ugly, obscure, difficult and clumsy. Writing simple programs using such tools could be a terrible nightmare.

By the other hand I've had good experiences with VB, VFP and RapidQ and since that was nothing similar in the Harbour world, I've took some things of those products and put it together in HMG.

But I've must admit that was a misconception from my part.

Harbour OOP implementation is very powerful and flexible enough to allow the creation of a simple and easy to use OOP layer for any purpose (including a GUI library).

My main goals were:

1. Hide all standard HMG windows and control handling peculiarities to the OOP programmers, in such way that their experience be similar to the one using Clipper predefined classes.

2. Keep the things simple in such way that preprocessor directives be not necessary.

Here is a sample that creates a main window and a frame inside it:

Code: Select all

	*-------------------------------------------------------*

	Local oFrame
	Local oWindow

	* Window Definition *

	With Object oWindow := Window():New()
		:Row         := 10
		:Col         := 10
		:Width       := 400
		:Height      := 400
		:Title	    := 'Nice OOP Demo!!!'
		:WindowType  := WND_MAIN
		:OnInit      := { || oWindow:Center() }
	End With

	* Frame Definition *

	With Object oFrame := Frame():New()
		:Parent      := oWindow
		:Row         := 10
		:Col         := 10
		:Width       := 350
		:Height      := 340
		:Caption     := 'This is an OOP Frame!!!'
	End With

	oWindow:Activate()
	*-------------------------------------------------------*
For traditionalists, the same thing can be achieved using the following code:

Code: Select all

	*-------------------------------------------------------*

	Local oFrame
	Local oWindow

	* Window Definition *

	oWindow := Window():New()

	oWindow:Row:= 10
	oWindow:Col:= 10
	oWindow:Width:= 400
	oWindow:Height:= 400
	oWindow:Title:= 'Nice OOP Demo!!!'
	oWindow:WindowType:= WND_MAIN
	oWindow:OnInit:= { || oWindow:Center() }

	* Control Definition *

	oFrame := Frame():New()

	oFrame:Parent:= oWindow
	oFrame:Row:= 10
	oFrame:Col:= 10
	oFrame:Width:= 350
	oFrame:Height:= 340
	oFrame:Caption:= 'Hi OOP!!!'

	oWindow:Activate()
	*-------------------------------------------------------*
At the moment the code must be considered experimental. It contains a complete OOP implementation for Window and Frame.

Enjoy!

PS: OOP programmers... Welcome to HMG too :)
Attachments
hmgoop_test_2.rar
(11.81 KiB) Downloaded 294 times
Regards/Saludos,

Roberto


(Veritas Filia Temporis)

User avatar
tave2009
Posts: 60
Joined: Tue Jul 14, 2009 3:33 am
Location: San Francisco, Córdoba, Argentina.
Been thanked: 1 time

Post by tave2009 » Mon May 03, 2010 1:56 am

Hola Roberto,
Primer error:

HMG Errorlog File

------------------------------------
Date:05/02/10 Time: 22:52:52
Error BASE/1086 Argument error: ++
Called from WINDOW:NEW(1200)
Called from MAIN(16)

------------------------------------
Saludos !
Walter
Nada se pierde. Todo se transforma. (Lavoussier)
Nothing is lost. Everything changes.

User avatar
Roberto Lopez
HMG Founder
Posts: 3980
Joined: Wed Jul 30, 2008 6:43 pm
Has thanked: 27 times
Been thanked: 168 times

Post by Roberto Lopez » Mon May 03, 2010 1:59 am

tave2009 wrote:Hola Roberto,
Primer error:

HMG Errorlog File

------------------------------------
Date:05/02/10 Time: 22:52:52
Error BASE/1086 Argument error: ++
Called from WINDOW:NEW(1200)
Called from MAIN(16)

------------------------------------
Saludos !
Walter
Al inicio de los demos Agregar / At demos start add:

_HMG_SYSDATA [ 323 ] := 0

Gracias por el aviso! / Thanks for the advise!
Regards/Saludos,

Roberto


(Veritas Filia Temporis)

User avatar
tave2009
Posts: 60
Joined: Tue Jul 14, 2009 3:33 am
Location: San Francisco, Córdoba, Argentina.
Been thanked: 1 time

Post by tave2009 » Mon May 03, 2010 2:17 am

Hola Roberto,
Esa misma línea la agrege al 'h_init .prg' de la carpeta \source y regeneré las libreria con el makelib.
Ahora funcionó bien.
Saludos
Hello Roberto,
That same code adds it to 'h_init.prg' in \source folder then regenerate the library with makelib.bat
and ready works well.
Regards.
Walter
Nada se pierde. Todo se transforma. (Lavoussier)
Nothing is lost. Everything changes.

User avatar
sudip
Posts: 1446
Joined: Sat Mar 07, 2009 11:52 am
Location: Kolkata, WB, India
Has thanked: 5 times
Been thanked: 1 time

Post by sudip » Mon May 03, 2010 2:41 am

Hello Roberto,

Thank you very much for thinking to use OOP with HMG :D

I was looking for this feature since I heard the name of Minigui about 1 and 4 months back :) Then I read your views about OPP and thought I couldn't write codes with HMG with VFP style.

I am very happy to see that my wish is coming true :D

With best regards.

Sudip
With best regards,
Sudip

User avatar
sistemascvc
Posts: 13
Joined: Wed Aug 06, 2008 10:00 pm
Contact:

Post by sistemascvc » Mon May 03, 2010 3:41 am

Hi Roberto:

A Question to you...

in the sample, when the window is really created?

when the code reach oWindow := Window():New()

or when oWindow:Activate()

regards
Ciro

User avatar
Roberto Lopez
HMG Founder
Posts: 3980
Joined: Wed Jul 30, 2008 6:43 pm
Has thanked: 27 times
Been thanked: 168 times

Post by Roberto Lopez » Mon May 03, 2010 4:13 am

sistemascvc wrote:Hi Roberto:

A Question to you...

in the sample, when the window is really created?

when the code reach oWindow := Window():New()

or when oWindow:Activate()

regards
Ciro
When the window is activated, all things are really created (the window and its controls).

If you need that a thing be created prior window activation, you can use 'Create()' method (available for window and controls).

I've done so (among other reasons) because I wanted a 'New()' method without parameters. This way there is nothing special to remember when an object is created, making easier to write.

Besides that, all properties has default values, so, you can write less code.

This way, I've achieved something that before I've believed not possible: A nice and easy OOP interface :)
Regards/Saludos,

Roberto


(Veritas Filia Temporis)

User avatar
sudip
Posts: 1446
Joined: Sat Mar 07, 2009 11:52 am
Location: Kolkata, WB, India
Has thanked: 5 times
Been thanked: 1 time

Post by sudip » Mon May 03, 2010 4:21 am

Roberto Lopez wrote:..
When the window is activated, all things are really created (the window and its controls).

If you need that an object be created prior window activation, you can use 'Create()' method (available for window and controls).

I've done so (among other reasons) because I wanted a 'New()' method without parameters. This way there is nothing special to remember when an object is created, making easier to write.

Besides that, all properties has default values, so, you can write less code.

This way, I've achieved something that before I've believed not possible: A nice and easy OOP interface :)
Great thinking, Roberto :)
I am really excited :D
With best regards,
Sudip

User avatar
sistemascvc
Posts: 13
Joined: Wed Aug 06, 2008 10:00 pm
Contact:

Post by sistemascvc » Mon May 03, 2010 4:31 am

the best way is that you choose.

I agree with you

if i need add a control after the window has been activated

how you do it? (the syntax)


best regards
Ciro

User avatar
Rathinagiri
Posts: 5264
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Has thanked: 169 times
Been thanked: 172 times
Contact:

Post by Rathinagiri » Mon May 03, 2010 5:01 am

Nice implementation Roberto. Go ahead.
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.

Post Reply