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

Execute a protected macro?
Goto page 1, 2  Next
 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API
View previous topic :: View next topic  
Author Message
ykcim
General User
General User


Joined: 15 Jul 2003
Posts: 21

PostPosted: Sat Feb 11, 2006 4:32 am    Post subject: Execute a protected macro? Reply with quote

Hi,

i have a problem with a protected library. (OO 2.0)
I use a document wth some macros in one library. I protected this library with a password. In this document ( a writer-form) is a button to execute a macro from the protected library.
If i open the document and press the button an get an errormessage:
Object not accessible. Invalid Object Reference

If i now only try to open the library, but don't do it, and press the button again the macro starts.
I copy the library in MyMacros and create a menuentry to execute the macro. But also i can start the macro only after i try to open the library.
Does any one have a hint for me?

Best Regards
Michael
Back to top
View user's profile Send private message Visit poster's website
B Marcelly
Super User
Super User


Joined: 12 May 2004
Posts: 1414
Location: France

PostPosted: Sat Feb 11, 2006 6:04 am    Post subject: Reply with quote

The problem is not related to the password protection. I think your macro opens a Basic dialog.
You have to load the dialog library before using it. Search the forum, I am sure there are many threads on the subject.
Back to top
View user's profile Send private message Visit poster's website
ykcim
General User
General User


Joined: 15 Jul 2003
Posts: 21

PostPosted: Sat Feb 11, 2006 7:22 am    Post subject: Reply with quote

Thanks. I searched one a new way.
The dialog library is load. And the error comes not if i use the library without protection.
But i use one dialog in another lib (unprotected).. Without protection without any problem, with protection it fails. I transfered the dialog in the same lib and all goes as i like.

Best Regards
Michael
Back to top
View user's profile Send private message Visit poster's website
gval
General User
General User


Joined: 27 Oct 2004
Posts: 20
Location: Winnipeg, MB

PostPosted: Tue Mar 21, 2006 9:04 am    Post subject: Need to explicitly load the Dialog Library Reply with quote

see http://www.oooforum.org/forum/viewtopic.phtml?t=16394&highlight=
Back to top
View user's profile Send private message
Pitounet
OOo Enthusiast
OOo Enthusiast


Joined: 26 May 2005
Posts: 172
Location: Toulouse / France

PostPosted: Wed Mar 22, 2006 1:45 am    Post subject: Reply with quote

Have a look at this 2 threads which deal with problem in protected libraries:
http://www.oooforum.org/forum/viewtopic.phtml?t=14174&highlight=protected
http://www.oooforum.org/forum/viewtopic.phtml?t=32372&highlight=protected

Antoine.
Back to top
View user's profile Send private message
Gastiflex
Power User
Power User


Joined: 29 Mar 2006
Posts: 70
Location: Toulouse - France

PostPosted: Wed Jun 14, 2006 1:57 am    Post subject: Reply with quote

Hi,
I've got the same problem : executing a protected macro generate an error
Object not accessible. Invalid Object Reference

I've read the previous threads, but I don't understand very well if someone has found a solution to the problem.
Back to top
View user's profile Send private message
Pitounet
OOo Enthusiast
OOo Enthusiast


Joined: 26 May 2005
Posts: 172
Location: Toulouse / France

PostPosted: Wed Jun 14, 2006 2:00 am    Post subject: Reply with quote

Previous threads give some clues if you are on one of thecases described.

Can you precise when/how your problem occur?

Antoine.
Back to top
View user's profile Send private message
Gastiflex
Power User
Power User


Joined: 29 Mar 2006
Posts: 70
Location: Toulouse - France

PostPosted: Wed Jun 14, 2006 2:30 am    Post subject: Reply with quote

I've got a library that works correctly (I launch the main sub with a button in the toolbar). I create a password to protect it, I restart OOo to apply the password, and when I click on the button, I've got the following message :
"Impossible d'accéder à l'objet. Référence d'objet incorrecte"
then
"Runtime error Basic. Variable indéfinie"

If I unlock the library, it works again.
Back to top
View user's profile Send private message
Pitounet
OOo Enthusiast
OOo Enthusiast


Joined: 26 May 2005
Posts: 172
Location: Toulouse / France

PostPosted: Wed Jun 14, 2006 3:58 am    Post subject: Reply with quote

Do you Type defined in your library.
(Code like:
Code:
Type Test
 test1 as Variant
End Type
)?
Back to top
View user's profile Send private message
Gastiflex
Power User
Power User


Joined: 29 Mar 2006
Posts: 70
Location: Toulouse - France

PostPosted: Wed Jun 14, 2006 4:30 am    Post subject: Reply with quote

I'm not sure to understand : do you mean that I can't use the keyword "Type" in a protected macro ?
Back to top
View user's profile Send private message
Pitounet
OOo Enthusiast
OOo Enthusiast


Joined: 26 May 2005
Posts: 172
Location: Toulouse / France

PostPosted: Wed Jun 14, 2006 4:51 am    Post subject: Reply with quote

Right, this is currently a bug : http://www.openoffice.org/issues/show_bug.cgi?id=62476
It won't be corrected before ... OOo 3.0...

What you can do is create another library not protected which contain all your types definitions...

I did not find another solution

Antoine.
Back to top
View user's profile Send private message
Gastiflex
Power User
Power User


Joined: 29 Mar 2006
Posts: 70
Location: Toulouse - France

PostPosted: Wed Jun 14, 2006 5:27 am    Post subject: Reply with quote

Ok, if I follow your example, I declare in the Standard non-protected library :
Code:

Type Test
 test1 as Variant
End Type


But in this case, I've got an unknown type error on this line in the protected library :
Code:

Dim newTest as Test


How can I use a type declared in another library ?
Back to top
View user's profile Send private message
Pitounet
OOo Enthusiast
OOo Enthusiast


Joined: 26 May 2005
Posts: 172
Location: Toulouse / France

PostPosted: Wed Jun 14, 2006 5:50 am    Post subject: Reply with quote

Type management is a bit complex.

In the same module where you define your type you "must" also create function to:
* Create a new variable of the Type.
* Copy a variable of the type to a new one.
* Create an array of variables of the type.

If you don't do that, your type won't be uable outside your module.

Try add the function

Code:
Function CreateTest as Test
 Dim test as Test
 'Init
 test.test1 = 0
 CreateTest = test
End Function


Then you can use anywhere:
Code:
Sub Testot
 Dim test
 test = CreateTest()
 MsgBox(test.test1)
End Sub


Does it work for you?

Antoine.
Back to top
View user's profile Send private message
Pitounet
OOo Enthusiast
OOo Enthusiast


Joined: 26 May 2005
Posts: 172
Location: Toulouse / France

PostPosted: Wed Jun 14, 2006 5:51 am    Post subject: Reply with quote

To be complete, only the creation function is really mandatory; but a copy and an array function are really useful when using a lot a defined type...
Back to top
View user's profile Send private message
Villeroy
Super User
Super User


Joined: 04 Oct 2004
Posts: 10065
Location: Germany

PostPosted: Wed Jun 14, 2006 6:07 am    Post subject: Reply with quote

Userdefined types are valid on module level.
For read/write-access to a module's type you need to create functions and subs.
Code:

REM Library "myLib", module "myModule"
Type myType
  Int as Integer
  Var as Variant
End Type
Global myTestVar as myType
Function getMyTestVar()
  getMyTestVar = myTestVar
End Function
Sub setMyTestVar(Int%,Var)
  myTestVar.Int = Int
  myTestVar.Var = Var
End Sub
REM return new struct with preset values
Function getNewMyType(Int%,Var)
Dim oStruct as new myType
  oStruct.Int = Int
  oStruct.Var = Var
  getNewMyType = oStruct
End Function

Code:

REM call from other module
Sub Foo
Dim oMyVar,int%,obj
int = 1
obj = thisComponent
oMyVar = myLib.myModule.getNewMyType(int,obj)
print oMyVar.Int ; oMyVar.Var.getURL
End Sub

_________________
Rest in peace, oooforum.org
Get help on http://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
Goto page 1, 2  Next
Page 1 of 2

 
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