CreateObject() ?

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

User avatar
Roberto Lopez
HMG Founder
Posts: 4023
Joined: Wed Jul 30, 2008 6:43 pm

CreateObject() ?

Post by Roberto Lopez »

Hi All,

I have the following problem:

I've successfully created and used an OLE object..

Code: Select all

	oObj := CreateObject('Something')
Then, I've invoked some method...

Code: Select all

	res := oObj:SomeMethod()
The problem is that 'res' is supposed to be an object, so, I should be able to get the following:

Code: Select all

	res:SomeProperty	
But, 'res' type is 'U'.

Any clue?

TIA.
Regards/Saludos,

Roberto


(Veritas Filia Temporis)
User avatar
AUGE_OHR
Posts: 2117
Joined: Sun Aug 25, 2019 3:12 pm
DBs Used: DBF, PostgreSQL, MySQL, SQLite
Location: Hamburg, Germany

Re: CreateObject() ?

Post by AUGE_OHR »

hi,
Roberto Lopez wrote: Sun Feb 23, 2020 2:12 am Then, I've invoked some method...

Code: Select all

	res := oObj:SomeMethod()
The problem is that 'res' is supposed to be an object, so, I should be able to get the following:

Code: Select all

	res:SomeProperty	
But, 'res' type is 'U'.
which Control are you using :?:

like a Function it is not usual to get back a Object .
if a Object have to be create than it might be another Interface.
have fun
Jimmy
User avatar
Roberto Lopez
HMG Founder
Posts: 4023
Joined: Wed Jul 30, 2008 6:43 pm

Re: CreateObject() ?

Post by Roberto Lopez »

AUGE_OHR wrote: Sun Feb 23, 2020 3:51 am hi,
Roberto Lopez wrote: Sun Feb 23, 2020 2:12 am Then, I've invoked some method...

Code: Select all

	res := oObj:SomeMethod()
The problem is that 'res' is supposed to be an object, so, I should be able to get the following:

Code: Select all

	res:SomeProperty	
But, 'res' type is 'U'.
which Control are you using :?:

like a Function it is not usual to get back a Object .
if a Object have to be create than it might be another Interface.
Is a Fiscal Printer OCX and I'm porting VB demos to HMG. All works fine except when I need respone data.

This is a piece of VB code (HASARNG is the object):

Code: Select all

    
    respabrir = HASARNG.AbrirDocumento(TiqueFacturaA)
    Debug.Print
    Debug.Print " - (abrir) Tique Factura 'A' Nro.  = [" & respabrir.NumeroComprobante & "]"
    Debug.Print
Regards/Saludos,

Roberto


(Veritas Filia Temporis)
User avatar
AUGE_OHR
Posts: 2117
Joined: Sun Aug 25, 2019 3:12 pm
DBs Used: DBF, PostgreSQL, MySQL, SQLite
Location: Hamburg, Germany

Re: CreateObject() ?

Post by AUGE_OHR »

hi,

do you have a Link to that OCX Product :?:

does these Link have to do with your OCX :?:
https://studylib.es/doc/6601888/impreso ... 3%B3n--2g-
https://www.mail-archive.com/gufa@mug.o ... 15489.html

it is hard to give a Tip when not have API Desription (or Source) to understand how Syntax work
it is easy when Return Value is a Pointer or String but what about a Structure :roll:

---

i´m not sure what harbour / HMG ACTIVEX can do but what i saw is "just" CreateObject() ... no "Subscript Event".
MiniGUI seem to have it but i have not test it yet

"Subscript Event" mean to receive Event from ACTIVEX not only Call Method or Invoke Property

---

under Xbase++ i use a 3-PP Tool : DispHelper ( https://sourceforge.net/projects/disphelper/ )
here you finde some Sample how to use it
http://disphelper.sourceforge.net/readme.htm
http://disphelper.sourceforge.net/
have fun
Jimmy
User avatar
danielmaximiliano
Posts: 2763
Joined: Fri Apr 09, 2010 4:53 pm
DBs Used: DBF
Location: Argentina
Contact:

Re: CreateObject() ?

Post by danielmaximiliano »

Hola Roberto,mi vieja aplicacion fue portada de usar la DLL ("Winfis.dll") a OCX de la siguiente forma

Code: Select all

#define c715F 'HASAR.Fiscal.1'
/*---------------------------------------------------------/
//    Los Tilos Versión OCX                                //
/---------------------------------------------------------*/
Function Main                         
LOCAL OCX_bSaveHandler
LOCAL OCX_Error   := 0 
Crea715f( )
..

Code: Select all

*------------------------------------------------------------------------------*
Function Crea715f( )
*------------------------------------------------------------------------------*
Return
    IF ( o715F := CreateObject( c715F ) ) != NIL
       o715F:puerto := 1
	   If ( cModelo := o715F:AutodetectarModelo( ) ) != NIL
		      PrincipalOCX.STATUSBAR.Item(2) := 'Impresora ' + Alltrim ( cModelo ) + ' Conectada a  ' + ;
			                                     Alltrim ( STR ( nPuerto ) )
		    else 	
			  PrincipalOCX.STATUSBAR.Item(2) := 'Impresora desconocida ' + ' Conectada a COM1 ' 
       EndIf
    Else
		Msgbox ( ' No se puede inicializar la IMPRESORA ' , ' Mensaje de error !!! ' )
    endIf		
		      
Return
al emitir un comprobante use parte de este ejemplo

Code: Select all

#include 'hmg.ch'
#include 'hfcl.ch'
/*
 Hasar1.Modelo = MODELO_615
Hasar1.Puerto = 1
Hasar1.Comenzar
Hasar1.TratarDeCancelarTodo
Hasar1.AbrirComprobanteFiscal TICKET_C
Hasar1.ImprimirItem "Artículo 1", 1, 100, 21, 0
Hasar1.Subtotal True
Hasar1.ImprimirPago "Efectivo", 100
Hasar1.CerrarComprobanteFiscal
Hasar1.Finalizar 

o 

TICKET_C = 84
MODELO_615 = 2
THISFORM.Olecontrol1.Puerto = 1
THISFORM.Olecontrol1.Modelo = MODELO_615
THISFORM.Olecontrol1.Comenzar
THISFORM.OleControl1.TratarDeCancelarTodo
THISFORM.Olecontrol1.AbrirComprobanteFiscal (TICKET_C)
THISFORM.Olecontrol1
.ImprimirItem ("Artículo 1", 1, 100, 21, 0)
THISFORM.Olecontrol1.Subtotal (.T.)
THISFORM.Olecontrol1.ImprimirPago ("Efectivo", 100)
THISFORM.Olecontrol1.CerrarComprobanteFiscal
THISFORM.Olecontrol1.Finaliza
*/

#define c715F          'HASAR.Fiscal.1'
************************************************************************
* HMG ejemplo utilizando OCX fiscal010724.ocx 
* Modelo: SMH/P-715F
************************************************************************

#define cOCUPADO_CMD			"Un comando se ejecutando, espere por favor un momento !!!"
#define cESTACION_TICKET 	"T"
#define cESTACION_SLIP		"S"
#define nTICKET_C			 84
#define nTICKET_FACTURA_A    65  
#define nTICKET_FACTURA_B    66  

****************************
* Eventos de Impresora
****************************
#define nP_PRINTER_ERROR			  4
#define nP_OFFLINE				     8
#define nP_JOURNAL_PAPER_LOW		 16
#define nP_RECEIPT_PAPER_LOW		 32
#define nnP_SLIP_PLATEN_OPEN		256
#define P_DRAWER_CLOSE			 16384

****************************
* Error Fiscal
****************************
#define nF_FISCAL_MEMORY_FAIL	      1
#define nF_WORKING_MEMORY_FAIL	      2
#define nF_UNRECOGNIZED_COMMAND	      8
#define nF_INVALID_FIELD_DATA	     16
#define nF_INVALID_COMMAND		     32
#define nF_TOTAL_OVERFLOW		     64
#define nF_FISCAL_MEMORY_FULL	    128
#define nF_DATE_SET_FAIL			2048
*#define Window Principal


Static cPath715F  := ''

#ifndef __XHARBOUR__
   #xcommand TRY  => BEGIN SEQUENCE WITH {|oErr| Break( oErr )}
   #xcommand CATCH [<!oErr!>] => RECOVER [USING <oErr>] <-oErr->
#endif
para enviar el comprobante lo manejo asi

Code: Select all

o715f:AbrirComprobanteFiscal ( 84 ) o o715f:AbrirComprobanteFiscal ( nTICKET_C )
o715f:ImprimirItem ( cXPL , 1 , Val ( cPrecio ) , 21 , 0 )
faltan detalles que uso, si es realmente lo que necesitas es eso te los envio . saludos y un Abrazo como siempre
PD: es necesario instalar el OCX te dejo el link http://grupohasar.com/producto/ocx-hasar/
*´¨)
¸.·´¸.·*´¨) ¸.·*¨)
(¸.·´. (¸.·` *
.·`. Harbour/HMG : It's magic !
(¸.·``··*

Saludos / Regards
DaNiElMaXiMiLiAnO

Whatsapp. := +54901169026142
Telegram Name := DaNiElMaXiMiLiAnO
Telegram invitation https://t.me/HMGWorkspace
User avatar
Roberto Lopez
HMG Founder
Posts: 4023
Joined: Wed Jul 30, 2008 6:43 pm

Re: CreateObject() ?

Post by Roberto Lopez »

AUGE_OHR wrote: Sun Feb 23, 2020 9:25 pm hi,

do you have a Link to that OCX Product :?:

does these Link have to do with your OCX :?:
https://studylib.es/doc/6601888/impreso ... 3%B3n--2g-
https://www.mail-archive.com/gufa@mug.o ... 15489.html

it is hard to give a Tip when not have API Desription (or Source) to understand how Syntax work
it is easy when Return Value is a Pointer or String but what about a Structure :roll:

---

i´m not sure what harbour / HMG ACTIVEX can do but what i saw is "just" CreateObject() ... no "Subscript Event".
MiniGUI seem to have it but i have not test it yet

"Subscript Event" mean to receive Event from ACTIVEX not only Call Method or Invoke Property

---

under Xbase++ i use a 3-PP Tool : DispHelper ( https://sourceforge.net/projects/disphelper/ )
here you finde some Sample how to use it
http://disphelper.sourceforge.net/readme.htm
http://disphelper.sourceforge.net/
I've found the problem and is not on Harbour OLE implementation.

According to the component manual, it returns 'data structures' that could be not available in the programming language that you are using.

So, since the demos are in VB and C#, I assume that the data structures returned are available in those languages and not in Harbour.

The component offers an alternative, for other languages, consisting of a method that accept as parameter the name of the property that you need and returns it.

Sadly this *very important* info is in a small section in a 50 page manual, when It should be in bold, capital letters at the beginning of the documentation :)

Many thanks for the help to all. I hope that my experience be useful for someone.

Regards,

Roberto.
Regards/Saludos,

Roberto


(Veritas Filia Temporis)
User avatar
Roberto Lopez
HMG Founder
Posts: 4023
Joined: Wed Jul 30, 2008 6:43 pm

Re: CreateObject() ?

Post by Roberto Lopez »

danielmaximiliano wrote: Tue Feb 25, 2020 12:25 pm Hola Roberto,mi vieja aplicacion fue portada de usar la DLL ("Winfis.dll") a OCX de la siguiente forma
Daniel,

Como siempre, muchas Gracias.

En lo que estoy trabajando, es en adaptar un punto de venta fiscal, que está funcionando en equipos Hasar de primera generación (715 y 441), a los de segunda generación (ya que los de primera, no se van a poder seguir usando el año próximo).

El problema (que descubrí hace un rato) es que los métodos no retornan variables, sino estructuras de datos, que no están disponibles en Harbour.

Por lo cual, después de cada comando (si queremos conocer su resultado y el estado del equipo) hay que usar un método que acepta como parámetro el nombre de la propiedad que queremos conocer y devuelve su contenido como una variable simple.

Por ejemplo:

Code: Select all

	oHasar:CerrarDocumento(, )
        
	res := oHasar:ObtenerCampoRespuesta('NumeroComprobante')

	msginfo(res)
Acá va el experimento que hice, portando partes de los ejemplos en VB (solo trae demos en VB y C#).
Las herramientas de desarrollo, incluyen un emulador, que es el que usé para hacer las pruebas (no las hice aun en un equipo físico).

Code: Select all

#define CRLF Chr( 13 ) + Chr( 10 )

#include "hmg.ch"

PROCEDURE MAIN()

	DEFINE WINDOW main_form ;
		AT 114,218 ;
		WIDTH 334 ;
		HEIGHT 276 ;
		TITLE 'TEST HASAR' ;
		MAIN

		DEFINE MAIN MENU

			DEFINE POPUP "Test"
				MENUITEM 'Reporte X' ACTION ReporteX()
				MENUITEM 'Reporte Z' ACTION ReporteZ()
				MENUITEM 'Factura A' ACTION FacturaA()
				MENUITEM 'Factura B' ACTION FacturaB()
				MENUITEM 'Salir'     ACTION EXIT PROGRAM
			END POPUP

		END MENU

	END WINDOW 

	Main_form.center
	Main_form.activate

RETURN

*------------------------------------------------------------------------------------------*
STATIC PROCEDURE ReporteX()
*------------------------------------------------------------------------------------------*
LOCAL oHasar

	TipoReporte_ReporteX := 88

	oHasar := CreateObject( "HasarArgentina.ImpresoraFiscalRG3561" )

	oHasar:Conectar("127.0.0.1")

	oHasar:CerrarJornadaFiscal(88)

	oHasar := nil

RETURN

*------------------------------------------------------------------------------------------*
STATIC PROCEDURE ReporteZ()
*------------------------------------------------------------------------------------------*
LOCAL oHasar

	TipoReporte_ReporteZ := 90

	oHasar := CreateObject( "HasarArgentina.ImpresoraFiscalRG3561" )

	oHasar:Conectar("127.0.0.1")

	oHasar:CerrarJornadaFiscal(TipoReporte_ReporteZ)

	oHasar := nil

RETURN

*------------------------------------------------------------------------------------------*
STATIC PROCEDURE FacturaA()
*------------------------------------------------------------------------------------------*
LOCAL oHasar

	oHasar := CreateObject( "HasarArgentina.ImpresoraFiscalRG3561" )

	oHasar:Conectar("127.0.0.1")

	ResponsableInscripto	:= 73
	TipoCUIT		:= 67
	TiqueFacturaA		:= 81
	Gravado			:= 7
	ModoSumaMonto		:= 77
	IIVariablePorcentual	:= 37
	DisplayNo		:= 48
	ModoPrecioBase		:= 66
	Unidad			:= 7
	Pagar			:= 84
	Efectivo		:= 8

  
	oHasar:CargarDatosCliente ( "Razón Social Cliente...", "99999999995", ResponsableInscripto, TipoCUIT, "Domicilio Cliente...", "Domicilio extensión 1...", "Domicilio extensión 2...", "Domicilio extensión 3...." )

	respabrir := oHasar:AbrirDocumento(TiqueFacturaA)

	oHasar:ImprimirItem ( "Item a la venta...", 1, 100, Gravado, 21, ModoSumaMonto, IIVariablePorcentual, 0.00000001, DisplayNo, ModoPrecioBase, 1, "779123456789", , Unidad )

	resppago := oHasar:ImprimirPago("Efectivo...", 90, Pagar, DisplayNo, , Efectivo, , "")
         
	respcierre := oHasar:CerrarDocumento(, "")

	oHasar := nil

RETURN

*------------------------------------------------------------------------------------------*
STATIC PROCEDURE FacturaB()
*------------------------------------------------------------------------------------------*
LOCAL oHasar

	* Constantes

	TiposDeResponsabilidadesCliente_Monotributo	:= 77
	TiposDeDocumentoCliente_TipoCUIT		:= 67
	TiposComprobante_TiqueFacturaB			:= 82
	CondicionesIVA_Gravado				:=  7
	ModosDeMonto_ModoSumaMonto			:= 77
	ModosDeImpuestosInternos_IIVariablePorcentual	:= 37
	ModosDeDisplay_DisplayNo			:= 48
	ModosDePrecio_ModoPrecioBase			:= 66
	UnidadesMedida_Unidad				:=  7
	ModosDePago_Pagar				:= 84
	TiposPago_Cheque				:= 3

	oHasar := CreateObject( "HasarArgentina.ImpresoraFiscalRG3561" )

	oHasar:Conectar("127.0.0.1")

	oHasar:CargarDatosCliente("Cliente Uno ...", "99999999995", TiposDeResponsabilidadesCliente_Monotributo, TiposDeDocumentoCliente_TipoCUIT, "Calle Uno, entre Dos y Tres, Nro. 1234 ...", , , )

	respabrir := oHasar:AbrirDocumento(TiposComprobante_TiqueFacturaB)

	oHasar:ImprimirItem("Producto Uno ...", 1.0, 131.0, CondicionesIVA_Gravado, 1.0, ModosDeMonto_ModoSumaMonto, ModosDeImpuestosInternos_IIVariablePorcentual, 10.0, ModosDeDisplay_DisplayNo, ModosDePrecio_ModoPrecioBase, 1, "7791234500001", "00001", UnidadesMedida_Unidad)

	oHasar:ImprimirPago("Medio de Pago Uno ..." , 30.46, ModosDePago_Pagar, ModosDeDisplay_DisplayNo, "", TiposPago_Cheque, 0, "")

	oHasar:CerrarDocumento(, )
        
	res := oHasar:ObtenerCampoRespuesta('NumeroComprobante')

	msginfo(res)

	oHasar := nil


RETURN

Espero que el código te sirva para cuando te toque migrar a impresoras 2G.

De nuevo, muchas Gracias.
Regards/Saludos,

Roberto


(Veritas Filia Temporis)
User avatar
AUGE_OHR
Posts: 2117
Joined: Sun Aug 25, 2019 3:12 pm
DBs Used: DBF, PostgreSQL, MySQL, SQLite
Location: Hamburg, Germany

Re: CreateObject() ?

Post by AUGE_OHR »

hi,

did you have some *.H Files in Demo Folder :?:
they often include used Structure
have fun
Jimmy
User avatar
Roberto Lopez
HMG Founder
Posts: 4023
Joined: Wed Jul 30, 2008 6:43 pm

Re: CreateObject() ?

Post by Roberto Lopez »

AUGE_OHR wrote: Wed Feb 26, 2020 6:17 am hi,

did you have some *.H Files in Demo Folder :?:
they often include used Structure
Sadly not.
Regards/Saludos,

Roberto


(Veritas Filia Temporis)
User avatar
HASA
Posts: 44
Joined: Sat Feb 23, 2013 3:00 pm
Location: SÃO PAULO - BRAZIL

Re: CreateObject() ?

Post by HASA »

- Hello Roberto, congratulations, does it have anything to do with a reserved word for resouce files or so?
HASA - São Paulo -Brazil
Post Reply