[Solved] Test Objects for identity

Creating a macro - Writing a Script - Using the API

[Solved] Test Objects for identity

Postby Lupp » Fri Jun 21, 2019 12:40 pm

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 6.2 and older versions, PortableOpenOffice 4.1.5 and older, StarOffice 5.2
---
Lupp from München
User avatar
Lupp
Volunteer
 
Posts: 2651
Joined: Sat May 31, 2014 7:05 pm
Location: München, Germany

Re: Test Objects for identity

Postby RoryOF » Fri Jun 21, 2019 12:48 pm

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.7 on Xubuntu 18.04.4 (mostly 64 bit version) and very infrequently on Win2K/XP
User avatar
RoryOF
Moderator
 
Posts: 30355
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Test Objects for identity

Postby JeJe » Fri Jun 21, 2019 1:30 pm

You could set a userdefinedattribute for the sheet to the URL when you assign the variable perhaps?
Openoffice 4.1.2
Windows 8
JeJe
Volunteer
 
Posts: 734
Joined: Wed Mar 09, 2016 2:40 pm

Re: Test Objects for identity

Postby Lupp » Fri Jun 21, 2019 1:57 pm

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 6.2 and older versions, PortableOpenOffice 4.1.5 and older, StarOffice 5.2
---
Lupp from München
User avatar
Lupp
Volunteer
 
Posts: 2651
Joined: Sat May 31, 2014 7:05 pm
Location: München, Germany

Re: Test Objects for identity

Postby Villeroy » Fri Jun 21, 2019 2:02 pm

The Ho Chi Minh trail from a cell (InitialTarget) down to the forms collection and up to the document:
Code: Select all   Expand viewCollapse view
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, no OpenOffice, LibreOffice 6.4
User avatar
Villeroy
Volunteer
 
Posts: 27700
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Test Objects for identity

Postby Lupp » Fri Jun 21, 2019 2:21 pm

@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 6.2 and older versions, PortableOpenOffice 4.1.5 and older, StarOffice 5.2
---
Lupp from München
User avatar
Lupp
Volunteer
 
Posts: 2651
Joined: Sat May 31, 2014 7:05 pm
Location: München, Germany

Re: [SOLVED] Test Objects for identity

Postby Lupp » Fri Jun 21, 2019 2:38 pm

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 6.2 and older versions, PortableOpenOffice 4.1.5 and older, StarOffice 5.2
---
Lupp from München
User avatar
Lupp
Volunteer
 
Posts: 2651
Joined: Sat May 31, 2014 7:05 pm
Location: München, Germany

Re: [SOLVED] Test Objects for identity

Postby Villeroy » Fri Jun 21, 2019 2:41 pm

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, no OpenOffice, LibreOffice 6.4
User avatar
Villeroy
Volunteer
 
Posts: 27700
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany


Return to Macros and UNO API

Who is online

Users browsing this forum: No registered users and 7 guests