Teste de OOP real

Projeto MiniGui - Biblioteca visual para Harbour/xHarbour

Moderador: Moderadores

Avatar do usuário
JoséQuintas
Administrador
Administrador
Mensagens: 20267
Registrado em: 26 Fev 2007 11:59
Localização: São Paulo-SP

Teste de OOP real

Mensagem por JoséQuintas »

Veio a idéia, testei e deu certo.

Código: Selecionar todos

CREATE CLASS ObjFromStack

   VAR aStack INIT {}

   METHOD New( ... )
   METHOD Center() INLINE DoMethod( hb_ArrayToParams( ::aStack ), "Center")
   METHOD Activate() INLINE DoMethod( hb_ArrayToParams( ::aStack ), "Activate")
   METHOD Value( xValue )
ENDCLASS

METHOD New( ... ) CLASS ObjFromStack

   ::aStack := hb_AParams()

   RETURN Self

METHOD Value( xValue ) CLASS ObjFromStack

   IF xValue != Nil
      SetProperty( hb_ArrayToParams( ::aStack ), "nValue", xValue )
   ELSE
      xValue := GetProperty( hb_ArrayToParams( ::aStack ), "Value" )
   ENDIF

   RETURN xValue
no exemplo:

Código: Selecionar todos

   oDlg := ObjFromStack():new(  xDlg )
   oDlg:Center()
   oDlg:Activate()

Código: Selecionar todos

         IF ! Empty( oDay )
            oCheck := ObjFromStack():New( xDlg, oDay )
            IF oCheck:Value
               cTxt += Dtoc( Stod( "2025" + StrZero( oMonth:__EnumIndex(), 2 ) + StrZero( oDay:__EnumIndex(), 2 ) ) ) + " "
            ENDIF
         ENDIF
Foi só teste, são tão poucas linhas, que usar OOP parece perda de tempo.
Mas vira OOP real, não a fake OOP dos CHs.
democalyearoop.zip
(2.08 KiB) Baixado 40 vezes
José M. C. Quintas
Harbour 3.2, mingw, gtwvg mt, fivewin 25.04, multithread, dbfcdx, MySQL, ADOClass, PDFClass, SefazClass, (hwgui mt), (hmg3), (hmg extended), (oohg), PNotepad, ASP, stored procedure, stored function, Linux (Flagship/harbour 3.2)
"The world is full of kings and queens, who blind our eyes and steal our dreams Its Heaven and Hell"

https://github.com/JoseQuintas/
Avatar do usuário
JoséQuintas
Administrador
Administrador
Mensagens: 20267
Registrado em: 26 Fev 2007 11:59
Localização: São Paulo-SP

Teste de OOP real

Mensagem por JoséQuintas »

Não sei se tem equivalente no xhabour.

Código: Selecionar todos

FUNCTION x( ... )
   x := hb_AParams()
hb_AParams() recebe todos os parâmetros como um array

Código: Selecionar todos

callfun( hb_ArrayAsParam(x), "Value" )
hb_ArrayAsParam() faz o contrário, transforma o array numa lista de parâmetros.
No exemplo acima ainda acrescenta "Value"

Aquilo de GetProperty( dialog, controle, "Value" ) ou DoMethod( dialog, "center" )
É essa lista que vai ser tratada, que não tem tamanho pré-determinado.

Código: Selecionar todos

oDlg := ObjFromStack( xDlg )
oCheck := ObjFromStack( xDlg, xCheck )
Praticamente uma tradução básica
oDlg:Activate() vai chamar DoMethod( xDlg, "Activate" )
oCheck:Value() vai chamar GetProperty( xDlg, xCheck, "Value" )

A diferença é que é real, vai existir em run-time, não é igual CH é só vale pro pré-compilador.
José M. C. Quintas
Harbour 3.2, mingw, gtwvg mt, fivewin 25.04, multithread, dbfcdx, MySQL, ADOClass, PDFClass, SefazClass, (hwgui mt), (hmg3), (hmg extended), (oohg), PNotepad, ASP, stored procedure, stored function, Linux (Flagship/harbour 3.2)
"The world is full of kings and queens, who blind our eyes and steal our dreams Its Heaven and Hell"

https://github.com/JoseQuintas/
Avatar do usuário
JoséQuintas
Administrador
Administrador
Mensagens: 20267
Registrado em: 26 Fev 2007 11:59
Localização: São Paulo-SP

Teste de OOP real

Mensagem por JoséQuintas »

Faltou dizer:

É naquele estilo que eu achei super-poderoso

Código: Selecionar todos

DEFINE DIALOG ( xDlg := ze_Name("DLG" ) )
Vai trabalhar com a variável xDlg, não importa o nome, o nome é gerado automático.
Só isso já é poderoso.
Se em algum lugar for vantagem, transforma isso em objeto com aquela função.
José M. C. Quintas
Harbour 3.2, mingw, gtwvg mt, fivewin 25.04, multithread, dbfcdx, MySQL, ADOClass, PDFClass, SefazClass, (hwgui mt), (hmg3), (hmg extended), (oohg), PNotepad, ASP, stored procedure, stored function, Linux (Flagship/harbour 3.2)
"The world is full of kings and queens, who blind our eyes and steal our dreams Its Heaven and Hell"

https://github.com/JoseQuintas/
Responder