COMate - control COM objects via automation - OBSOLETE!
ahhh...so you think maybe the monitor is not detected because the switcher is actually the device the OS is seeing and not the monitor?
That kind of makes sense in a way because the switcher would not be detected in the monitor class. (I don't think it would at least.)
That kind of makes sense in a way because the switcher would not be detected in the monitor class. (I don't think it would at least.)
Last edited by SFSxOI on Sat Sep 06, 2008 8:02 pm, edited 1 time in total.
-
- PureBasic Expert
- Posts: 2812
- Joined: Fri Apr 25, 2003 4:51 pm
- Location: Portugal, Lisbon
- Contact:
Need help:
Can't pass an array to the method
VB CODE
PB code (i want to pass an empty array)
Old DispHelp code (works)
Can't pass an array to the method

VB CODE
Code: Select all
Dim oSM, ODesk as Object 'root object from OOo API
Dim oDoc as Object 'The document to be opened
Dim OpenPar(2) As Object 'a Visual Basic array, with 3 elements
'Instanciate OOo : the first line is always required from Visual Basic for OOo
Set oSM = CreateObject("com.sun.star.ServiceManager")
Set oDesk = oSM.createInstance("com.sun.star.frame.Desktop")
'We call the MakePropertyValue function, defined just before, to access the structure
Set OpenPar(0) = MakePropertyValue("ReadOnly", True)
Set OpenPar(1) = MakePropertyValue("Password", "secret")
Set OpenPar(2) = MakePropertyValue("Hidden", False)
'Now we can call the OOo loadComponentFromURL method, giving it as
'fourth argument the result of our precedent MakePropertyValue call
Set oDoc = oDesk.loadComponentFromURL("file:///c|test.sxw", "_blank", 0, OpenPar)
Code: Select all
XIncludeFile "COMate.pbi"
XIncludeFile "VariantHelper_Include.pb"
Define.COMateObject oSM, oDesk, oDoc
Dim Array.SAFEARRAY(0)
document.s = "file:///" + GetCurrentDirectory() + "test.odt"
oSM = COMate_CreateObject("com.sun.star.ServiceManager")
If oSM
oDesk = oSM\GetObjectProperty("createInstance('com.sun.star.frame.Desktop')")
If oDesk
document.s = "file:///" + GetCurrentDirectory() + "test.ott"
document.s=ReplaceString(document,"\","/")
oDoc = oDesk\invoke("loadComponentFromURL('"+document+"','_blank',0,"+Str(@Array())+")")
;oDoc = oDesk\GetObjectProperty("loadComponentFromURL('"+document+"','_blank',0,"+Str(@Array())+")")
Debug oDoc
Debug COMate_GetLastErrorDescription()
EndIf
oDesk\Release()
oSM\Release()
EndIf
Code: Select all
Define ocurseur, mdoc, chaine.s, document.s
Define.l oSM, oDesk, oDoc, oSrch, oCursor, Hit
XIncludeFile "DispHelper_Include.pb"
XIncludeFile "VariantHelper_Include.pb"
Define.safearray *openpar
Define.variant openarray
V_ARRAY_DISP(openarray) = *openpar
dhToggleExceptions(#True)
oSM = dhCreateObject("com.sun.star.ServiceManager")
If oSM
;Creating instance of Desktop
dhGetValue("%o", @oDesk, oSM, ".CreateInstance(%T)", @"com.sun.star.frame.Desktop")
;Opening a new writer Document
document.s = "file:///" + GetCurrentDirectory() + "test.ott"
document.s = ReplaceString(document, "\", "/")
dhGetValue("%o", @oDoc, oDesk, ".loadComponentFromURL(%T,%T,%d,%v)", @document, @"_blank", 0, openarray)
dhReleaseObject(oDoc)
dhReleaseObject(oDesk)
dhReleaseObject(oSM)
EndIf
It's a high quality monitor from CTX with Plug & Pray support.
Not a Discounter Monitor with flickering Screen, is only a very old Monitor
Not a Discounter Monitor with flickering Screen, is only a very old Monitor
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.

Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.

@Num3 : I've uploaded a test version of Comate.pbi here for you to try with the following code :
I don't have open office with which to perform any tests on the code so it's down to you! It may take us a few attempts to get it working! 
**EDIT : if this doesn't work then I am thinking there looks to be a problem with the VariantHelper include with the V_ARRAY_DISP macro. I think that Arg\ppdispVal should read Arg\parray; not that it will make much difference I guess because it is a structureunion anyhow!
Code: Select all
XIncludeFile "COMate.pbi"
XIncludeFile "VariantHelper_Include.pb"
Define.COMateObject oSM, oDesk, oDoc
Define.safearray *openpar
Define.variant openarray
V_ARRAY_DISP(openarray) = safearray
oSM = COMate_CreateObject("com.sun.star.ServiceManager")
If oSM
;Creating instance of Desktop
oDesk = oSM\GetObjectProperty("CreateInstance('com.sun.star.frame.Desktop')")
If oDesk
;Opening a new writer Document
document.s = "file:///" + GetCurrentDirectory() + "test.ott"
document.s = ReplaceString(document, "\", "/")
oDoc = oDesk\GetObjectProperty("loadComponentFromURL('" + document + "', '_blank', 0, " + Str(openarray) + " as variant)")
If oDoc
oDoc\Release()
EndIf
oDesk\Release()
EndIf
oSM\Release()
EndIf

**EDIT : if this doesn't work then I am thinking there looks to be a problem with the VariantHelper include with the V_ARRAY_DISP macro. I think that Arg\ppdispVal should read Arg\parray; not that it will make much difference I guess because it is a structureunion anyhow!

Last edited by srod on Sat Sep 06, 2008 10:31 pm, edited 2 times in total.
I may look like a mule, but I'm not a complete ass.
@Num3
All codes, incl. the new by srod doesn't work with OpenOffice 3, so i can't
test it. I think the code works only for OpenOffice 2.x
All codes, incl. the new by srod doesn't work with OpenOffice 3, so i can't
test it. I think the code works only for OpenOffice 2.x
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.

Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.

As i say, i have no OO 2 to test, i have only OO 3 beta 2 installed. In OO 3srod wrote:@ts-soft, does my code above (with the test version of COMate) work with OO 2? I had overlooked variant type method parameters! :roll:
comes no object, so i think the name is another.
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.

Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.

-
- PureBasic Expert
- Posts: 2812
- Joined: Fri Apr 25, 2003 4:51 pm
- Location: Portugal, Lisbon
- Contact:
Found the problem!
I was forgetting to convert the filename to an URL encoded string!
I also spelled the document extension wrong .ott instead of .odt !
Here's a working example, works with OpenOffice 2/3 and also with IBM Symphony (aka Open Office with less bugs
)
Here's an example to open an empty document:
I was forgetting to convert the filename to an URL encoded string!
I also spelled the document extension wrong .ott instead of .odt !
Here's a working example, works with OpenOffice 2/3 and also with IBM Symphony (aka Open Office with less bugs

Code: Select all
XIncludeFile "COMate.pbi"
XIncludeFile "VariantHelper_Include.pb"
Procedure.s ConvertToUrl(strFile.s)
strFile = ReplaceString(strFile, "\", "/")
strFile = ReplaceString(strFile, ":", "|")
strFile = ReplaceString(strFile, " ", "%20")
strFile = "file:///" + strFile
ProcedureReturn strFile
EndProcedure
Define.COMateObject oSM, oDesk, oDoc
Define.safearray *openpar
Define.variant openarray
V_ARRAY_DISP(openarray) = safearray
oSM = COMate_CreateObject("com.sun.star.ServiceManager")
If oSM
;Creating instance of Desktop
oDesk = oSM\GetObjectProperty("CreateInstance('com.sun.star.frame.Desktop')")
If oDesk
;Opening a exisiting Document
document.s = GetCurrentDirectory() + "test.odt"
oDoc = oDesk\GetObjectProperty("loadComponentFromURL('"+ConvertToUrl(document)+"', '_blank', 0, " + Str(openarray) + " as variant)")
Debug COMate_GetLastErrorDescription()
If oDoc
oDoc\Release()
EndIf
oDesk\Release()
EndIf
oSM\Release()
EndIf
Code: Select all
XIncludeFile "COMate.pbi"
XIncludeFile "VariantHelper_Include.pb"
Procedure.s ConvertToUrl(strFile.s)
strFile = ReplaceString(strFile, "\", "/")
strFile = ReplaceString(strFile, ":", "|")
strFile = ReplaceString(strFile, " ", "%20")
strFile = "file:///" + strFile
ProcedureReturn strFile
EndProcedure
Define.COMateObject oSM, oDesk, oDoc
Define.safearray *openpar
Define.variant openarray
V_ARRAY_DISP(openarray) = safearray
oSM = COMate_CreateObject("com.sun.star.ServiceManager")
If oSM
;Creating instance of Desktop
oDesk = oSM\GetObjectProperty("CreateInstance('com.sun.star.frame.Desktop')")
If oDesk
;Opening a new writer Document
oDoc = oDesk\GetObjectProperty("loadComponentFromURL('private:factory/swriter', '_blank', 0, " + Str(openarray) + " as variant)")
If oDoc
oDoc\Release()
EndIf
oDesk\Release()
EndIf
oSM\Release()
EndIf
Last edited by Num3 on Sun Sep 07, 2008 9:37 am, edited 1 time in total.