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

Why Libraries must be registered twice?
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
rafen
Newbie
Newbie


Joined: 07 Mar 2006
Posts: 4

PostPosted: Tue Mar 07, 2006 12:50 am    Post subject: Why Libraries must be registered twice? Reply with quote

Have created some special calc functions for calc. During the time I'm working on new created functions in the basic editor I can use them directly in the calc document to test.

After save - close - open the document the function (which was saved in a lib together with the document) is no more recognized. I have to copy the same library to "My Macros & Dialogs" then close and reopen the document to get the functions back to work.

It is exactly the same issue if I save libraries only in "My Macros & Dialogs". I cannot use the functions until I append the lib also to the calc document, close and reopen it.

Why I have to save a library in "My Macros & Dialogs" and the document at the same time to reuse it later on?????

If I gonna change later on a function in the lib, which library I have to change to get instance access to my changes?

Some more information
By accident I've found, that if the functions are saved in the "standard" container of the document, they are recognized even without copy the whole stuff to the program area itself. The trouble starts just at the time I try to use macros from my own libs which are part of a document.
Back to top
View user's profile Send private message
noranthon
Super User
Super User


Joined: 07 Jul 2005
Posts: 3323

PostPosted: Tue Mar 07, 2006 8:20 pm    Post subject: Reply with quote

If you put the functions in some library (in My Macros & Dialogs) other than Standard, you need a macro in Standard which loads the library when OO is launched. Otherwise, you have to open the Organizer and double-click on the library name before you can use the macros in it.

For the functions in a document library, you may need a macro which loads the library when you open the document. I was under the impression that the standard library in a document was automatically loaded but perhaps that is not so.
Back to top
View user's profile Send private message Visit poster's website
rafen
Newbie
Newbie


Joined: 07 Mar 2006
Posts: 4

PostPosted: Wed Mar 08, 2006 5:56 am    Post subject: Yes but Reply with quote

YES see the point, thanks for the answer.

BUT have found a macro which loads my library at document open. The good news are it's working, the bad news are don't know why.
Here's the macro code:
[color=green][code]
Sub Load_Library
dim sc as string
sc = "myLib"
if not BasicLibraries.isLibraryLoaded(sc) then
BasicLibraries.loadLibrary(sc)
Bluff 'add and remove a new named range
endif
End Sub

Sub Bluff
dim oCellAddress as new com.sun.star.table.CellAddress
oCellAddress.Sheet = 0
oCellAddress.Column = 0
oCellAddress.Row = 0
if not ThisComponent.namedRanges.hasByName("pqrst") then
ThisComponent.namedRanges.addNewByName("pqrst", "", oCellAddress, 0)
endif
ThisComponent.namedRanges.removeByName("pqrst")
End Sub[/code][/color]

Can anybod explain to me, what Bluff does and why it is really needed?
Back to top
View user's profile Send private message
grog
General User
General User


Joined: 28 Feb 2006
Posts: 24

PostPosted: Wed Mar 08, 2006 8:28 am    Post subject: Reply with quote

Dear Rafen,

I am having a similiar kind of probelm...can you give more detatils of where you put your macro 'load_library' and other, was that in standard in openoffice.org or your new libraries or my macros....and how you got it to regcognise your new libraries (we have a linux system with shared users)? I am in the spreadsheet. I guess I am asking for as much details as you can share..I am new to OO and so the learning curve is steep !!

Thanks

Grog
Back to top
View user's profile Send private message
noranthon
Super User
Super User


Joined: 07 Jul 2005
Posts: 3323

PostPosted: Wed Mar 08, 2006 6:11 pm    Post subject: Reply with quote

Rafen, you do not need the subroutine "Bluff". It was of some use to the person who devised the loading macro you are using. It names the first cell in the document "pqrst". Who knows why? Please answer grog.
Back to top
View user's profile Send private message Visit poster's website
uros
Super User
Super User


Joined: 22 May 2003
Posts: 601
Location: Slovenia

PostPosted: Wed Mar 08, 2006 11:12 pm    Post subject: Reply with quote

Hi all!
This Bluff thing isn't mine. I assume that author try to show how to access to Bluff sub, which is stored in a library called "myLib". Because sub isn't in the "Standard" library it isn't reachable directly, library where sub is included have to be loaded first (OOo at start loads only Standard library). So sub "LoadLibrary" first loads library "myLib", then starts sub Bluff.
Bluff realy do nothing realy smart, but it doesn't matter. There could be only MsgBox("Hello world") in it instead...
Hope it is understandable...
Uros
Back to top
View user's profile Send private message
rafen
Newbie
Newbie


Joined: 07 Mar 2006
Posts: 4

PostPosted: Wed Mar 08, 2006 11:28 pm    Post subject: Hmmmm Reply with quote

Bluff is NEED!

If you don't believe try it. If I just load the library without calling Buff, my macros in the loaded library won't be recognized and executed.

If I call Bluff after loading the library, then my macro from the loaded library will be executed. I assume, that somehing during the execution of Bluff triggers the whole calc sheet to recalculate/ reload everiting. So I think it is as side effect of executing Bluff which triggers also the macros to run.

Will try to explain in detail what I'm doing:
Have a calc sheet called marotest.
There in I have my special lib macrotestLib.
Inside macrotest lib is a stupid macro called macrotestAdd:
[code]Function macrotestAdd (val1 as Integer, val2 as Integer) as Integer
macrotestAdd=val1+ val2
end Function[/code]

Inside the calc sheet I've put in one cell =macrotestAdd(B1;B2)
In the Standard lib of the document I have my LoadLibrary macro as described before.
The LoadLibrary macro I've added to the document open event (Tools->Customize->Events->Open Document->Assign Macro)
Save everyting close the document. Open it again. If Bluff is called during LoadLibrary you will see immediately the correct result of macrotestAdd.
If Bluff is commented out you will just see #NAME?
Back to top
View user's profile Send private message
noranthon
Super User
Super User


Joined: 07 Jul 2005
Posts: 3323

PostPosted: Thu Mar 09, 2006 1:03 am    Post subject: Reply with quote

I've tried to replicate what you describe by transferring a function to a library called "General" and including a macro to load that library in the "Standard" library. The function, which served perfectly well in "Standard", now returns #VALUE!. I tried to run Bluff (which I also inserted in "General") but the line beginning "If not ..." generates the error "property or method not found" which is too weird for me at this end of the day so I am signing off and hope someone can shed some light on these events. It's a pity Uros has signed off. Shocked Shocked Shocked
Back to top
View user's profile Send private message Visit poster's website
rafen
Newbie
Newbie


Joined: 07 Mar 2006
Posts: 4

PostPosted: Thu Mar 09, 2006 5:52 am    Post subject: Wrong locations Reply with quote

LoadLibrary and Bluff must be located in the Standard library of the calc sheet. That's the only way to bring the whole thing to live.
Back to top
View user's profile Send private message
noranthon
Super User
Super User


Joined: 07 Jul 2005
Posts: 3323

PostPosted: Thu Mar 09, 2006 6:01 pm    Post subject: Reply with quote

It's better to tussle with these things when you are not tired. This is what I have:
1. Two functions which work well in the user library "Standard".
2. The same functions work when placed in the "Standard" library of a Calc document - without any special procedure to load them. I believe that in that location they only work when that document is open; I haven't tried to use them when the document is not open because the result, I think, would inevitably be failure.
3. I tried moving the functions to a user library named "General". I also inserted a macro into that library to load the library and assigned that macro to Document Open. Including the Bluff command in that macro made a difference: the functions, instead of returning #NAME?, returned #VALUE!.
I agree, therefore, that running Bluff makes a difference in that situation. Like you, I do not know why. I tried substituting ThisComponent.calculateAll() which made no difference to the result of the functions and ThisComponent.refresh() which was not recognised and generated an error.
I tried putting the load macro and Bluff macro in the Standard library of the test document. Presumably, the "General" library was loaded but the functions returned #NAME? whether Bluff was called or not.

Macros in a document library can be used with that document.

If you wish to make the functions available to all users, I believe they can be placed in a system library.


Last edited by noranthon on Tue Aug 08, 2006 4:48 am; edited 1 time in total
Back to top
View user's profile Send private message Visit poster's website
uros
Super User
Super User


Joined: 22 May 2003
Posts: 601
Location: Slovenia

PostPosted: Thu Mar 09, 2006 11:02 pm    Post subject: Reply with quote

Good morning, noranthon! Cool
I totaly agree with you. If user function is in Standard library (of file or user or shared library) it is usable directly, because Standard libraries are loaded at start of OOo or when the file is loaded. There is no need to load them explicitly.
Unfortunately I didn't manage to use function if it is in any other library! No library loading or starting some macros in them helped... Neither in OOo 1.1.x or 2.0.1.
If anybody can do that, please be so kind and share the knowledge...
Uros
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: Fri Mar 10, 2006 1:16 am    Post subject: Reply with quote

Hi all,

I had the problem to create a tool (I will call it "MyTool") which creates other documents where some macros of "MyTool" must be used directly.

The macro library of MyTool was very specific and can't be System libraries.

The only solution I found was to create dynamically a menu to use these macros. Once created the menu is also availble in the other documents.
The menu will be removed once OOo is closed.

Menus let me give a full path to my macro:
Code:
sMyCommand = "macro://MyTool/MyLib.AboutDialog.Show_Tools_About()"



Antoine.
Back to top
View user's profile Send private message
noranthon
Super User
Super User


Joined: 07 Jul 2005
Posts: 3323

PostPosted: Fri Mar 10, 2006 6:01 pm    Post subject: Reply with quote

There are various ways of accessing macros generally. The use of user-defined functions in the Calc document is another issue and the one raised in the original post. Locating such functions other than in a "Standard" library seems to make them unavailable, even if the library is loaded. (System libraries may be different; I have not tested that.)
Back to top
View user's profile Send private message Visit poster's website
pitonyak
Administrator
Administrator


Joined: 09 Mar 2004
Posts: 3152
Location: Columbus, Ohio, USA

PostPosted: Fri Mar 10, 2006 9:37 pm    Post subject: Reply with quote

I just created functions in the Standard library and in Library1, both contained in a Calc document. I used 2.02 Windows version. I was able to call both versions as a Calc function no problem.

After creating the function in the non-standard library, did you leave the IDE open? Did you refocus the IDE to a different library?

All of this stuff might matter...

I left the IDE open, but I went from my new library back to the Standard library. Then, with both functions defined, I entered my two calls in my calc document.

If you can not call the functions, this is probably a BUG and should be reported.
_________________
--
Andrew Pitonyak
My Document: http://www.pitonyak.org/AndrewMacro.odt
Free Info: http://www.pitonyak.org/oo.php
Most hated bug: http://www.openoffice.org/issues/show_bug.cgi?id=84159
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address
noranthon
Super User
Super User


Joined: 07 Jul 2005
Posts: 3323

PostPosted: Fri Mar 10, 2006 11:07 pm    Post subject: Reply with quote

I can confirm what you say. I've just created Library1 in a document and successfully called a function created in it. In addition to functions in Standard libraries, I only previously tested functions created in a user library other than Standard; the last cannot be called (at least in 2.0.1 on Linux).
Back to top
View user's profile Send private message Visit poster's website
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