| View previous topic :: View next topic |
| Author |
Message |
ykcim General User

Joined: 15 Jul 2003 Posts: 21
|
Posted: Sat Feb 11, 2006 4:32 am Post subject: Execute a protected macro? |
|
|
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 |
|
 |
B Marcelly Super User

Joined: 12 May 2004 Posts: 1145 Location: France
|
Posted: Sat Feb 11, 2006 6:04 am Post subject: |
|
|
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 |
|
 |
ykcim General User

Joined: 15 Jul 2003 Posts: 21
|
Posted: Sat Feb 11, 2006 7:22 am Post subject: |
|
|
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 |
|
 |
gval General User

Joined: 27 Oct 2004 Posts: 20 Location: Winnipeg, MB
|
|
| Back to top |
|
 |
Pitounet OOo Enthusiast


Joined: 26 May 2005 Posts: 172 Location: Toulouse / France
|
|
| Back to top |
|
 |
Gastiflex Power User

Joined: 29 Mar 2006 Posts: 70 Location: Toulouse - France
|
Posted: Wed Jun 14, 2006 1:57 am Post subject: |
|
|
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 |
|
 |
Pitounet OOo Enthusiast


Joined: 26 May 2005 Posts: 172 Location: Toulouse / France
|
Posted: Wed Jun 14, 2006 2:00 am Post subject: |
|
|
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 |
|
 |
Gastiflex Power User

Joined: 29 Mar 2006 Posts: 70 Location: Toulouse - France
|
Posted: Wed Jun 14, 2006 2:30 am Post subject: |
|
|
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 |
|
 |
Pitounet OOo Enthusiast


Joined: 26 May 2005 Posts: 172 Location: Toulouse / France
|
Posted: Wed Jun 14, 2006 3:58 am Post subject: |
|
|
Do you Type defined in your library.
(Code like: | Code: | Type Test
test1 as Variant
End Type | )? |
|
| Back to top |
|
 |
Gastiflex Power User

Joined: 29 Mar 2006 Posts: 70 Location: Toulouse - France
|
Posted: Wed Jun 14, 2006 4:30 am Post subject: |
|
|
| I'm not sure to understand : do you mean that I can't use the keyword "Type" in a protected macro ? |
|
| Back to top |
|
 |
Pitounet OOo Enthusiast


Joined: 26 May 2005 Posts: 172 Location: Toulouse / France
|
Posted: Wed Jun 14, 2006 4:51 am Post subject: |
|
|
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 |
|
 |
Gastiflex Power User

Joined: 29 Mar 2006 Posts: 70 Location: Toulouse - France
|
Posted: Wed Jun 14, 2006 5:27 am Post subject: |
|
|
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 |
|
 |
Pitounet OOo Enthusiast


Joined: 26 May 2005 Posts: 172 Location: Toulouse / France
|
Posted: Wed Jun 14, 2006 5:50 am Post subject: |
|
|
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 |
|
 |
Pitounet OOo Enthusiast


Joined: 26 May 2005 Posts: 172 Location: Toulouse / France
|
Posted: Wed Jun 14, 2006 5:51 am Post subject: |
|
|
| 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 |
|
 |
Villeroy Super User


Joined: 04 Oct 2004 Posts: 7649 Location: Germany
|
Posted: Wed Jun 14, 2006 6:07 am Post subject: |
|
|
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
|
_________________ XUbuntu 9.04, OOo 3.1.1(Sun), Sun Java 1.5.0_06 |
|
| Back to top |
|
 |
|