[Solved] Test Objects for identity

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
User avatar
Lupp
Volunteer
Posts: 3552
Joined: Sat May 31, 2014 7:05 pm
Location: München, Germany

[Solved] Test Objects for identity

Post by Lupp »

Suppose I have two files, created by storeToURL from the same SpreadsheetDocument without any changes in-between.

Later I opened both these copies from user code and chose TWICE one of these two components RANDOMLY from the StarDesktop both times assigning the first sheet to an object variable, the first time to vari1, the second time to vari2.

How can I distinguish between vari1, vari2 being two ways of access to the SAME thing and vari1, vari2 pointing to DIFFERENT objects only having every property beyond the origin in common.

Precautionary remark:
EqualUNOObjects ALWAYS returns FALSE for sheets, ranges, cells and the like, even for the same object created in the same way twice.
I could not yet find a property pointing "upwards" from a sheet (like .Parent or .Component or .Model or ...).
This looks strange to me. However, even for TextDocument where everything seems to point upwards and often infinitely loops back to self from seemingly subordinate properties, nothing points to the model. This MIGHT be intended. For security/saftey? For what reasons?
Last edited by Lupp on Fri Jun 21, 2019 2:25 pm, edited 5 times in total.
On Windows 10: LibreOffice 24.2 (new numbering) and older versions, PortableOpenOffice 4.1.7 and older, StarOffice 5.2
---
Lupp from München
User avatar
RoryOF
Moderator
Posts: 34618
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Test Objects for identity

Post by RoryOF »

This may be a manifestation of the underlying code (C++?), dealing with variables "by reference" or "by value". If one could access their address in RAM, identical addresses might indicate "by reference". There may be other methods of resolving this problem.
Apache OpenOffice 4.1.15 on Xubuntu 22.04.4 LTS
JeJe
Volunteer
Posts: 2784
Joined: Wed Mar 09, 2016 2:40 pm

Re: Test Objects for identity

Post by JeJe »

You could set a userdefinedattribute for the sheet to the URL when you assign the variable perhaps?
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
User avatar
Lupp
Volunteer
Posts: 3552
Joined: Sat May 31, 2014 7:05 pm
Location: München, Germany

Re: Test Objects for identity

Post by Lupp »

Yes and thanks for your interest.
Well, I wouldn't even need to assign anything to the object, if I keep it as one element of an array or a structure where the other element is the model from which it was taken or something identifying it.

The question is more about understanding the "Why? - Or is it different?". A specific application would be a way to pass a cell / cellrange to a Sub/Function, not needing to pass anything else even if the routine needs access to different sheets or to any property of the model for its working.

Insofar you may see my starting point in the question:
"How can I get as an object the SpreadsheetDocument a sheet passed as a Var parameter to a routine belongs to?"

As soon as I have a reliable test for identity, I can at least find a workaround concerning the second (and more practical) question by comparing any given sheet whith any equally named and equally indexed sheet of any .SpreadsheetDocument accessible via the StarDesktop.
Last edited by Lupp on Fri Jun 21, 2019 2:08 pm, edited 1 time in total.
On Windows 10: LibreOffice 24.2 (new numbering) and older versions, PortableOpenOffice 4.1.7 and older, StarOffice 5.2
---
Lupp from München
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Test Objects for identity

Post by Villeroy »

The Ho Chi Minh trail from a cell (InitialTarget) down to the forms collection and up to the document:

Code: Select all

Sub Snippet(Optional oInitialTarget As Object)
  Dim oSpreadsheet As Variant
  Dim oDrawPage As Variant
  Dim oForms As Variant
  Dim oParent As Variant
  Dim sURL As String

  oSpreadsheet = oInitialTarget.getSpreadsheet()
  oDrawPage = oSpreadsheet.getDrawPage()
  oForms = oDrawPage.getForms()
  
  oParent = oForms.getParent()
  sURL = oParent.getURL()
End Sub
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
User avatar
Lupp
Volunteer
Posts: 3552
Joined: Sat May 31, 2014 7:05 pm
Location: München, Germany

Re: Test Objects for identity

Post by Lupp »

@Villeroy:
You are a great guerilla fighter, obviously! Did you find that path using your warrior's guide, or was there a stroke of ingeniousness? Second alternative surely!
"So einfach - und man kommt nicht drauf!" (I much less use forms than you do.)
Anyway, a conscious decision to not allow the access to the model based on a subordinate object should be ruled out by that. Oddrr?
On Windows 10: LibreOffice 24.2 (new numbering) and older versions, PortableOpenOffice 4.1.7 and older, StarOffice 5.2
---
Lupp from München
User avatar
Lupp
Volunteer
Posts: 3552
Joined: Sat May 31, 2014 7:05 pm
Location: München, Germany

Re: [SOLVED] Test Objects for identity

Post by Lupp »

The problem is solved concerning the secondary, more practical question.
Concerning the original topic in general I may have to wait for results in pursuit of this bug report to the TDF: https://bugs.documentfoundation.org/sho ... ?id=125421.
On Windows 10: LibreOffice 24.2 (new numbering) and older versions, PortableOpenOffice 4.1.7 and older, StarOffice 5.2
---
Lupp from München
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: [SOLVED] Test Objects for identity

Post by Villeroy »

I stumbled over it when looping through a hierarchy of forms, subforms and form controls down and then up again. The surprising thing is that you go down from a sheet's draw page into the forms hierarchy and calling getParent several times, you finally land on the document itself.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Post Reply