On Nov 24, 2009, at 9:26 AM, Leandro Damasio wrote:
> Hi,
>
> My name is Leandro Damasio and I have started to follow Harbour Project Main
> Developer List few days ago. I recently started 2D Informatica with my
> associate Ted, to develop commercial aplications using [x]Harbour. We used
> xHarbour + BCC55 + HWGUI for about 3 years, until we read xhb-diff.txt
> document and decided to try Harbour instead.
>
> We are about to realease 2DWGUI, an Object Oriented Harbour API to Win32 GUI,
> and its going to be a free product but not opensource from start.
>
> Our experience with opensource development is minimal, but I believe we could
> be useful by giving sugestions and/or reporting problems at least.
>
> My first try:
>
> Does harbour have native support to singleton classes? Its an useful design
> pattern to declare unique instance objects, so the same instance is
> reacheable/accessible globally by just calling for the the class name.
> We implemented Singleton objects in xHarbour, but I'm sure the native
> implementation should be done better by someone who knows the object machine
> inside.
>
> The Singleton Class usage is like below:
>
> <code>
>
> CLASS Aplication SINGLETON
>
> DATA Status
>
> METHOD Init(aParams)
> METHOD Run()
> METHOD End()
>
> ENDCLASS
>
>
> Procedure Main (...)
>
> Aplication():Init(hb_aParams())
>
> Func2()
>
> Aplication():End()
>
> Return
>
>
> Static Function Func2()
>
> Aplication():Run()
>
> Return Aplication():Status
>
> </code>
Hi Leandro,
In wxHarbour I've implemented this in the way that wxWidgets does, in fact you
need to implement the same setup (closely) in wxWidgets for C++ that in
wxHarbour:
In every wxWidget application you need to instance a subclass from the wxApp
class (at least you must do it for GUI apps, console ones doesn't require
wxApp), the wxApp class is used among other things for:
- Start the main application process by calling the ::OnInit() method
- Start the main GUI app message/event loop
- Contain application wide properties and method's.
A typically wxHarbour app, would be:
<prg>
#include "wxharbour.ch"
FUNCTION Main()
IMPLEMENT_APP( MyApp():New() )
RETURN NIL
CLASS MyApp FROM wxApp
PRIVATE:
PROTECTED:
PUBLIC:
DATA frame
METHOD OnInit()
PUBLISHED:
ENDCLASS
METHOD FUNCTION OnInit() CLASS MyApp
CREATE FRAME ::frame ;
TITLE "Frame1"
@ BUTTON "ShowTitle" ACTION {|| wxMessageBox( wxGetApp():frame:GetTitle() ) }
SHOW WINDOW ::frame FIT CENTRE
RETURN .T.
</prg>
The "MyApp" class is instantiated in the "Main" function, and it can be
retrieved anywhere in the app by using the "wxGetApp()" function, so it can be
used in a application wide way.
>
> If it is not implemented yet, do you think its a good idea to implement
> natively?
I don't understand what do you mean by natively, if you mean to:
- Limit the number of instances
- automate the instantiation
- calling in the app
I think that it can be done easily by simply using the Harbour's Preprocessor
capabilities.
best regards,
Teo
_______________________________________________
Harbour mailing list (attachment size limit: 40KB)
[email protected]
http://lists.harbour-project.org/mailman/listinfo/harbour