OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

Function call by name

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API
View previous topic :: View next topic  
Author Message
ekleinod
General User
General User


Joined: 04 Jan 2012
Posts: 6

PostPosted: Thu Feb 02, 2012 7:20 am    Post subject: Function call by name Reply with quote

Hi,

I want to call an (basic) function by it's name, not directly. If figured out, I could use "executeDispatch" for this purpose, but I am not able to pass parameters to the function.

If this was solved previously, I would be delighted for a link to the solution, I did not find a similar thread.

I tried as follows:
Code:
Sub testRPC
   Dim oTestDH      As Variant
   Dim sTestURL   As String
   Dim oNoArgs()   As new com.sun.star.beans.PropertyValue
   Dim oParams(0)   As new com.sun.star.beans.PropertyValue

   MsgBox("True (direct): " & testMe(True))
   MsgBox("False (direct): " & testMe(False))
   
   oTestDH = createUnoService("com.sun.star.frame.DispatchHelper")
   sTestURL = "macro:///Standard.Module1.testMe"

   oParams(0).Name = "bFlag"
   oParams(0).Value = True
   ' Variant 1
   MsgBox("True (dispatch): " & oTestDH.executeDispatch(StarDesktop, sTestURL, "", 0, oParams()))
   ' Variant 2
   MsgBox("True (dispatch): " & oTestDH.executeDispatch(StarDesktop, sTestURL & "(True)", "", 0, oNoArgs()))

   oParams(0).Value = False
   MsgBox("False (dispatch): " & oTestDH.executeDispatch(StarDesktop, sTestURL, "", 0, oParams()))
End Sub

Function testMe(bFlag As Boolean) As String
   If (isMissing(bFlag)) Then
      testMe = "no parameter"
   Else
      If (bFlag) Then
         testMe = "trueee"
      Else
         testMe = "faaaalse"
      End If
   End If
End Function

The direct function calls work, the dispatched calls do not. They call the function correctly but the parameter causes an error:

Variant 1 returns that the argument is not optional.

Variant 2 returns wrong value for property (I think, roughly translated from German)

Maybe there is a better solution without dispatches? Or maybe dispatches work and I do not use them correctly?

Thanks for suggestions,

Ekkart.
Back to top
View user's profile Send private message
hanya
Super User
Super User


Joined: 04 May 2005
Posts: 543
Location: Japan

PostPosted: Fri Feb 03, 2012 10:52 am    Post subject: Reply with quote

Hi,

I have not tried to execute macro with argument though dispatch mechanism but the following notation might be work:
Code:
macro://Lib.Mod.Sub(arg1, arg2, ...)


There is a mechanism to execute script though api and it allows to execute macros with arguments. See: http://www.oooforum.org/forum/viewtopic.phtml?t=23310&highlight=createscriptprovider
Back to top
View user's profile Send private message
Villeroy
Super User
Super User


Joined: 04 Oct 2004
Posts: 10106
Location: Germany

PostPosted: Sat Feb 04, 2012 11:53 am    Post subject: Reply with quote

The URL to call a Basic macro is like:
vnd.sun.star.script:Library.Module.Subroutine?language=Basic&location=document (or &location=application)
At least this is what works with a hyperlink in some document.
_________________
Rest in peace, oooforum.org
Get help on https://forum.openoffice.org
Back to top
View user's profile Send private message
ekleinod
General User
General User


Joined: 04 Jan 2012
Posts: 6

PostPosted: Tue Feb 07, 2012 3:09 am    Post subject: Reply with quote

@hanya This would be the call as in Variant 2, it does not work in my example.

@Villeroy How do I set parameters in this case?

Thanks,

Ekkart.
Back to top
View user's profile Send private message
Villeroy
Super User
Super User


Joined: 04 Oct 2004
Posts: 10106
Location: Germany

PostPosted: Tue Feb 07, 2012 9:23 am    Post subject: Reply with quote

ekleinod wrote:
@hanya This would be the call as in Variant 2, it does not work in my example.

@Villeroy How do I set parameters in this case?

Thanks,

Ekkart.

Add your own arguments to the URL. The called Basic macro gets the full URL as argument.
Example with a simple URL parser: http://user.services.openoffice.org/en/forum/download/file.php?id=152
_________________
Rest in peace, oooforum.org
Get help on https://forum.openoffice.org
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group