Hi Roberto,
Your OOP code is very elegant and very simple and yet very powerful. You have established the base class of the controls for which all controls can inherit. I tried to experiment with your sample. I modified Test1 and added grid on it.
Unfortunately I am not successful. On the first try, while running the program, the supposed to be window does not display at all. No error log, it simply exit. A little later I added an altd() debugger call and inserted oGrid1:Hide() right before oWindow.Activate. It gives me this error message:
Control: _HMG_OBJECT_3 Of _HMG_OBJECT_1 Not defined. Program Terminated
Called from DOMETHOD(7426)
Called from GRID:HIDE(128)
Called from MAIN(58)
In the OOPLIB.PRG I added this line: Set Procedure To lib\grid
In the spirit of learning I followed the FRAME Class and the GRID Class source code looks like this:
Code: Select all
#include "hbclass.ch"
#include "common.ch"
*..............................................................................*
* Class Grid ..................................................................*
*..............................................................................*
CLASS GRID FROM CONTROL
* Internal Data
DATA Tooltip INIT NIL
DATA aHeaders INIT {}
DATA aWidths INIT {}
DATA aRows INIT {}
DATA value INIT {0,0}
DATA nogrid INIT .F.
DATA aImage INIT {}
DATA aJust INIT {}
DATA break INIT .F.
DATA HelpId INIT NIL
DATA bold INIT .F.
DATA italic INIT .F.
DATA underline INIT .F.
DATA strikeout INIT .F.
DATA ownerdata INIT .T.
DATA ondispinfo INIT {}
DATA itemcount INIT 0
DATA available0 INIT .T.
DATA available1 INIT .T.
DATA available2 INIT .T.
DATA multiselec INIT .F.
DATA available3 INIT .F.
DATA backcolor INIT {}
DATA fontcolor INIT {}
DATA inplace INIT .F.
DATA editcontrols INIT NIL
DATA dynamicbackcolor INIT {}
DATA dynamicforecolor INIT {}
DATA columnvalid INIT {}
DATA columnwhen INIT {}
DATA columnheaders INIT {}
DATA aHeaderImages INIT NIL
DATA cellnavigation INIT .T.
DATA recordsource INIT NIL
DATA columnfields INIT NIL
DATA append INIT .F.
DATA buffered INIT .T.
DATA allowdelete INIT .F.
DATA dynamicdisplay INIT NIL
DATA OnChange INIT NIL
DATA DblClick INIT NIL
DATA aHeadClick INIT NIL
DATA GotFocus INIT NIL
DATA LostFocus INIT NIL
DATA OnSave INIT NIL
* Methods
METHOD Create()
* Events
METHOD Onchange INLINE EVAL ( ::OnChange )
METHOD Ondblclick INLINE EVAL ( ::DblClick )
METHOD OnaHeadClick INLINE EVAL ( ::aHeadClick )
METHOD Ongotfocus INLINE EVAL ( ::GotFocus )
METHOD Onlostfocus INLINE EVAL ( ::LostFocus )
METHOD Onsave INLINE EVAL ( ::OnSave )
ENDCLASS
*..............................................................................*
* Methods .....................................................................*
*..............................................................................*
METHOD Create() CLASS GRID
_DefineGrid ( ::cName, ;
::cParent, ;
::nRow, ;
::nCol, ;
::nWidth,;
::nHeight, ;
::aHeaders , ;
::aWidths , ;
::aRows , ;
::value , ;
::fontname , ;
::fontsize , ;
::tooltip , ;
::Onchange , ;
::DblClick , ;
::aHeadClick , ;
::GotFocus , ;
::LostFocus , ;
::nogrid , ;
::aImage , ;
::aJust , ;
::break , ;
::HelpId , ;
::bold , ;
::italic , ;
::underline , ;
::strikeout , ;
::ownerdata , ;
::ondispinfo , ;
::itemcount , ;
::available0 , ;
::available1 , ;
::available2 , ;
::multiselect , ;
::available3 , ;
::backcolor , ;
::fontcolor , ;
::inplace , ;
::editcontrols , ;
::dynamicbackcolor ,;
::dynamicforecolor ,;
::columnvalid , ;
::columnwhen , ;
::columnheaders , ;
::aHeaderImages , ;
::cellnavigation , ;
::recordsource , ;
::columnfields , ;
::append , ;
::buffered , ;
::allowdelete , ;
::dynamicdisplay , ;
::OnSave )
::lCreated := .T.
RETURN Self
This is the test source code including my altd() call:
Code: Select all
#include "include\hmgoop.ch"
Set Procedure To lib\OopLib
Function Main
Local oFrame
Local oWindow
local oGrid1
PRIVATE aRows_ := ARRAY( 20 )
_HMG_SYSDATA [ 323 ] := 0
SetTestData()
* 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 and Grid!!!'
End With
with object oGrid1 := Grid():New()
:Parent := oWindow
:Row := 15
:Col := 15
:Width := 330
:Height := 320
:aHeaders := { "Last Name", "First Name", "Phone" }
:aWidths := { 100, 200, 100 }
:aRows := aRows_
:Value := {1,1}
End with
altd()
oGrid1:Hide()
oWindow:Activate()
Return
static function SetTestData()
aRows_[1] := {'Simpson','Homer','555-5555'}
aRows_[2] := {'Mulder','Fox','324-6432'}
aRows_[3] := {'Smart','Max','432-5892'}
aRows_[4] := {'Grillo','Pepe','894-2332'}
aRows_[5] := {'Kirk','James','346-9873'}
aRows_[6] := {'Barriga','Carlos','394-9654'}
aRows_[7] := {'Flanders','Ned','435-3211'}
aRows_[8] := {'Smith','John','123-1234'}
aRows_[9] := {'Pedemonti','Flavio','000-0000'}
aRows_[10] := {'Gomez','Juan','583-4832'}
aRows_[11] := {'Fernandez','Raul','321-4332'}
aRows_[12] := {'Borges','Javier','326-9430'}
aRows_[13] := {'Alvarez','Alberto','543-7898'}
aRows_[14] := {'Gonzalez','Ambo','437-8473'}
aRows_[15] := {'Batistuta','Gol','485-2843'}
aRows_[16] := {'Vinazzi','Amigo','394-5983'}
aRows_[17] := {'Pedemonti','Flavio','534-7984'}
aRows_[18] := {'Samarbide','Armando','854-7873'}
aRows_[19] := {'Pradon','Alejandra','???-????'}
aRows_[20] := {'Reyes','Monica','432-5836'}
return
My intention in doing this is to see how the exe file would grow, if HMG and OOPLib could run side by side (I believed it would because classes have their own separate space) and the application performance in terms of speed and stability.
Your OOP experimental code is a new world to be explore and it's thrilling to play with.
I have a feeling that my problem lies on the class DATA initialization of the GRID & of course those bugs on my code.
Congrats and thank you very much for drafting a new toy for us!
Regards,
Danny