From b5af3b0f7341cc95a482e756210b31381ed737f0 Mon Sep 17 00:00:00 2001 From: Mindaugas Kavaliauskas Date: Thu, 23 Sep 2010 03:04:11 +0000 Subject: [PATCH] 2010-09-23 06:05 UTC+0300 Mindaugas Kavaliauskas (dbtopas/at/dbtopas.lt) * harbour/contrib/hbwin/olecore.c + added possibility to use more than one parameter in property put call. This allows to make a workaround for non-existant Harbour language syntax: object.name(param) = value Workaround syntax: object._name(param, value) + added comment documenting OLE automation behaviour for various VBScript sentences + harbour/contrib/hbwin/tests/pdfcreat.prg + added sample code for producing .pdf documents using OLE and PDFCreator --- harbour/ChangeLog | 13 ++++ harbour/contrib/hbwin/olecore.c | 23 ++++++- harbour/contrib/hbwin/tests/pdfcreat.prg | 85 ++++++++++++++++++++++++ 3 files changed, 120 insertions(+), 1 deletion(-) create mode 100644 harbour/contrib/hbwin/tests/pdfcreat.prg diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 555af436ac..e7c28172e5 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -16,6 +16,19 @@ The license applies to all entries newer than 2009-04-28. */ +2010-09-23 06:05 UTC+0300 Mindaugas Kavaliauskas (dbtopas/at/dbtopas.lt) + * harbour/contrib/hbwin/olecore.c + + added possibility to use more than one parameter in property put + call. This allows to make a workaround for non-existant Harbour + language syntax: + object.name(param) = value + Workaround syntax: + object._name(param, value) + + added comment documenting OLE automation behaviour for various + VBScript sentences + + harbour/contrib/hbwin/tests/pdfcreat.prg + + added sample code for producing .pdf documents using OLE and PDFCreator + 2010-09-22 18:48 UTC-0800 Pritpal Bedi (bedipritpal@hotmail.com) * contrib/hbqt/qtgui/qth/QBoxLayout.qth * contrib/hbqt/qtgui/qth/QComboBox.qth diff --git a/harbour/contrib/hbwin/olecore.c b/harbour/contrib/hbwin/olecore.c index 351a70efdb..c771ea64c6 100644 --- a/harbour/contrib/hbwin/olecore.c +++ b/harbour/contrib/hbwin/olecore.c @@ -1490,6 +1490,27 @@ HB_FUNC( WIN_OLEERRORTEXT ) } } +/* + +VBScript and Harbour syntax and IDispatch:Invoke() usage differences + +VBScript syntax dispid DISPATCH_* flags argcnt | Harbour syntax :Invoke parameters +================================================================+======================================= +obj DISPID_VALUE METHOD+PROPERTYGET 0 | Same :Invoke is not used +obj() DISPID_VALUE METHOD 0 | Not supported +obj(param) DISPID_VALUE METHOD+PROPERTYGET 1 | obj[param] Same +obj.name name METHOD+PROPERTYGET 0 | Same, =obj.name() Same +obj.name() name METHOD 0 | Same, =obj.name flags=METHOD+PROPERTYGET +obj.name(param) name METHOD+PROPERTYGET 1 | Same Same + | +obj = value obj reassigned, :Invoke is not used | Same +obj() = value DISPID_VALUE PROPERTYPUT 1 | Not supported +obj(param) = value DISPID_VALUE PROPERTYPUT 2 | obj[param] = value +obj.name = value name PROPERTYPUT 1 | Same Same +obj.name() = value name PROPERTYPUT 1 | Not supported, use obj.name = value +obj.name(param) = value name PROPERTYPUT 2 | Not supported, workaround obj._name(param, value) + +*/ HB_FUNC( WIN_OLEAUTO___ONERROR ) { @@ -1521,7 +1542,7 @@ HB_FUNC( WIN_OLEAUTO___ONERROR ) /* Try property put */ - if( szMethod[ 0 ] == '_' && hb_pcount() == 1 ) + if( szMethod[ 0 ] == '_' && hb_pcount() >= 1 ) { pMemberArray = &szMethodWide[ 1 ]; lOleError = HB_VTBL( pDisp )->GetIDsOfNames( HB_THIS_( pDisp ) HB_ID_REF( IID_NULL ), &pMemberArray, diff --git a/harbour/contrib/hbwin/tests/pdfcreat.prg b/harbour/contrib/hbwin/tests/pdfcreat.prg new file mode 100644 index 0000000000..64ca23a9ee --- /dev/null +++ b/harbour/contrib/hbwin/tests/pdfcreat.prg @@ -0,0 +1,85 @@ +/* + * $Id$ + */ + +/* + * Harbour Project source code + * Demonstration code for generating .pdf documents using PDFCreator + * COM interface. + * + * You should install PDFCreator to be able to run this test + * + * Download site: + * http://sourceforge.net/projects/pdfcreator/ + * + * COM interface docs: + * http://www.pdfforge.org/content/com-interface + * + * Copyright 2010 Mindaugas Kavaliauskas + * www - http://harbour-project.org + * + */ + +PROC main() +LOCAL oPC, nTime, cDefaultPrinter, cFilename, oPrinter, nEvent := 0 + + IF EMPTY( oPC := WIN_OLECreateObject( "PDFCreator.clsPDFCreator" ) ) + ? "Unable to create PDFCreator COM object" + RETURN + ENDIF + + cFilename := HB_PROGNAME() + + /* Setup event notification */ + oPC:__hSink := __AxRegisterHandler( oPC:__hObj, {|X| nEvent := X}, "{58B69879-9ED8-468D-879F-787161FA105F}") + + oPC:cStart( "/NoProcessingAtStartup" ) + oPC:_cOption( "UseAutosave", 1 ) + oPC:_cOption( "UseAutosaveDirectory", 1 ) + oPC:_cOption( "AutosaveDirectory", LEFT( cFileName, RAT( HB_PS(), cFilename ) - 1 ) ) + oPC:_cOption( "AutosaveFilename", "pdfcreat.pdf" ) + oPC:_cOption( "AutosaveFormat", 0 ) + + cDefaultPrinter := oPC:cDefaultPrinter + oPC:cDefaultPrinter := "PDFCreator" + oPC:cClearCache() + + /* You can do any printing here using WinAPI or + call a 3rd party application to do printing */ +#if 1 + oPrinter := Win_Prn():New( "PDFCreator" ) + oPrinter:Create() + oPrinter:startDoc( "Harbour print job via PDFCreator" ) + oPrinter:NewLine() + oPrinter:NewLine() + oPrinter:TextOut( "Hello, PDFCreator! This is Harbour :)" ) + oPrinter:EndDoc() + oPrinter:Destroy() +#else + ? "Do some printing to PDFCreator printer and press any key..." + INKEY(0) +#endif + + oPC:cPrinterStop := .F. + + nTime := hb_milliseconds() + DO WHILE nEvent == 0 .AND. hb_milliseconds() - nTime < 10000 + hb_idleSleep( 0.5 ) + /* The following dummy line is required to allow COM server to send event [Mindaugas] */ + oPC:cOption("UseAutosave") + ENDDO + + IF nEvent == 0 + ? "Print timeout" + ELSEIF nEvent == 1 + ? "Printed successfully" + ELSEIF nEvent == 2 + ? "Error:", oPC:cError():Description + ELSE + ? "Unknown event" + ENDIF + + oPC:cDefaultPrinter := cDefaultPrinter + oPC:cClose() + oPC := NIL +RETURN