Results 1 to 10 of 23

Thread: Class related Stuff New Instancing

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #14
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    10,457
    Rep Power
    10

    Rory 2

    Rory 2
    Rory 13 May 2016 https://www.excelforum.com/excel-pro...ml#post4386388


    Rory 13 may 2016 https://www.excelforum.com/excel-pro...ml#post4386412
    Me 13 May 2016 https://www.excelforum.com/excel-pro...ml#post4386421
    Rory 13 May 2016 https://www.excelforum.com/excel-pro...ml#post4386463
    Me 13 May 2016 https://www.excelforum.com/excel-pro...ml#post4386465

    Rory 13 maqy 2016 https://www.excelforum.com/excel-pro...ml#post4386894
    Me 14 may 2016 https://www.excelforum.com/excel-pro...ml#post4386898

    Rory 15 may 2016 https://www.excelforum.com/excel-pro...ml#post4387099
    Me 15 May 2016 https://www.excelforum.com/excel-pro...ml#post4387191

    https://www.excelfox.com/forum/showt...ll=1#post24211




    What is complicated here? It was a pointer to one range, then it was assigned another. At no point is there anything that could be called copying. I'm afraid I genuinely don't understand where you're going with this.


    _.________
    But you were talking about a copy of an object. That is not at all the same thing as a copy of a pointer.
    As I said, I may have once used the word copy out of context.
    or
    I may have been putting the argument forward of a Copy again , as I had not up until post #20 from shg seen a confirmation of the Local Copy idea. But I did always say words to the effect a “Copy “ made at the Call. So Really I was implying a locally made Copy...


    Apologies again for any confusion.


    I might prefer to say from now on to say
    “The Local Variable of the same type as the original made at the time of the Call to refer to a Pigeon Hole of similar construction to that of the Original Variable, ( Same variable Type ) This will be given a copy of the Original’s “Pointer, Code instruction paper or what ever”.

    I have said words to that effect more often than not.

    That may help to offset the confusion ... I doubt...

    _....

    Edit:
    Actually i cannot see where I used it out of context..? you unintentionally quoted it or read it out of context maybe
    It would appear to me that for **Objects and most variable Types a local copy is made in a called routine, **yes I suggest even for an Object. - Otherwise there would be no way to change that actuall Object in the routine as you can clearly do.
    For the ByVal call for an Object a copy of the Pointer is made which does refer to the original Object, so you cannot change the original Object, but can change its Properties. But a new “Pigeon Hole memory location” is created by the Called routine and instructions referring to actually changing the object ( and copying across as it were its Properties ) are included and can be made. As with all ByVal variables everything about them dies at the end of the called routine. These two Objects are simply sharing the same memory Locations containing all the values of all the Properties. The instruction part referring to Values referring to the Object itself, its address for example, are based on an offset to the relavent Pigeon Hole Location.
    .
    ……....... A New instance is a NewObject... or so I thought... And I would say again... you do make a local Copy of an Object..( and everything else ) . Or said a bit differently you use a temporary variable of the same type. ByVal.. But it dies at the end of the code....
    .....

    As long as you understand the "local copy" did not refer to a copy of the original object.
    Sounds good
    That is what I meant, but had not had it confirmed, so occasionally a slip of thought or whatever and I did not always make that clear.

    14 may 2016
    _ Is shg ( When a procedure gets an object ByVal, it gets a copy of the pointer to the object. You are free to change the object, e.g.,
    rng(1,1).value = "bob"
    ... and free to to assign the pointer to a different object internal to the called routine, e.g.,
    set rng = rng.offset(1)
    ... but in the latter case, the pointer is unchanged in the calling routine; the called routine just changed the local copy.
    ) talking about the part of the Pointer which contains info about things like the Address. shg says it’s not a typo
    A pointer is a variable that contains a memory address.
    Thanks for that.
    No offence, I am very grateful for your help.
    But, as I mentioned before, it makes things very difficult when you give such short answers like this.
    ( maybe you are just amusing yourself ?- why not – your well earned privilege )

    So It is not clear exactly what you are referring to there as the local copy.
    I could guess that could be the local copy of the Pointer?
    But is this "Pointer" somewhere ( maybe in a Pigeon Hole or whatever )
    So is "that" then effectively changed, or the contents there in. ?
    Such a thing could be the “Local Variable Copy” ( Just not too upset Rory I will emphasise it is not a Copy of the Object , in the same sense that for example, something like a Long number it would be the local Copy Variable that would also be a copy of everything to do with a Long Number. So it would be a Copy of the Long Number. In the case of the Object this Local Copy Variable is a Copy of the Pointer and is itself somehow an “Object” or else we could not change it within the called routine

    _......
    I suspect you "know" what you are talking about.
    I, and i bet many others , sadly do not

    It would be so great if you could expand a bit on what you said, preferably in terms a Laymen like me could understand

    And if not, thanks anyway again for coming back here.
    I myself ( in my profession ) had many frustrating hours trying to explain things that were obvious to me to others who had no idea. I feel your pain Alan
    shg An object pointer is a memory address that points to an object (more precisely, its vTable (Virtual Function ~), which contains the names of the object's properties and methods, the arguments they require, and their entry points (memory addresses)).

    When an object is passed by reference, the same pointer used by the calling procedure is passed to the called procedure. If the called procedure changes the pointer (by assigning it to a different object), that change is reflected in the calling procedure when the called procedure terminates.

    When passed by value, the calling procedure passes a COPY of the pointer. The called procedure can still do anything it likes, including changing (its local copy of) the pointer, but the copy is discarded when the called procedure terminates, so the calling procedure's pointer is unchanged.

    Rory 15 may 2016 [color=Blue]A pointer is a Long (or LongPtr on 64bit Office). The number it contains is a memory address (to the vTable of whichever interface was declared for the object variable, since an object can implement more than one). So passing it ByRef or ByVal is the same as passing a Long.[/color]
    Hi Rory,
    Thanks for the reply.


    Not sure if
    shg: ....The only thing there is a copy of is a four-byte pointer.
    and
    You, Rory: A pointer is a Long (or LongPtr on 64bit Office)....
    Are saying the same, may be ?
    _.....................
    and
    A pointer is a Long (or LongPtr on 64bit Office). The number it contains is a memory address .... So passing it ByRef or ByVal is the same as passing a Long.
    _.. I am afraid that makes no sense to me. Presumably then if I copy the pointer I copy a Long number.?!
    _.. If I meet a builder in the town who is prepared to sort my house as after 20 years I am still not getting anywhere, he will require my Address, etc...
    _. Say f I have a piece of paper with my Address on it, and instructions of what / where I want stuff and stuff done. Then it makes no difference if I give him that paper and he references that or if he copies the paper and references that.
    _..Never mind
    _.. Thanks again everyone. It has helped me get as far as I need.

    _................................................. ..................

    Thread Summary.

    _1) the initial theme, Set __ = ___ or Set ___ = New ____ ( as example the Worksheet was used )
    and maybe inevitably it has digressed a bit into

    _2 ) General Declaring of variables, how they are handled in passing , with particular emphasis with regard to the differing to the general rule of the Object variable.
    _...
    So
    _ 1 )
    Set __ = ____
    and
    Set ___ = New ____

    It lead to the Theme of Instancing.
    A code in Post # 11 summarised the Theme of instancing. Instancing briefly could be regarded as “making New”. This means a Virgin copy of the “Blue Print / Template / un filled in form of instructions on how to build something.” for the Object Class.
    Generally something we are “given” such as a Worksheet will not be a “Virgin” Blue Print. It is highly likely then that it will be very dependent on other existing things. Whilst not theoretically impossible to do, creating a New virgin instance of such will involve some complicated “wiring”. Generally the option to do that is not given to us. We are given the option of copying an existing instance to effectively give a New instance. A code was also tacked on in the code Window which both does this adding and shows what effectively done internally to get a new instance of a worksheet through .Add Method
    So in Post # 13 a suggested summary again

    ‘ Generally for Objects where there is dependency, that is to say....... they cannot exist independently and / or there are other Objects which are affected by the existence of such Objects..... , you will not be allowed to make a New Instance. Instancing by the user directly will not be allowed. This is likely because there will be some very complicated "Wiring" involved. There will need to be information given, for example, as "where should it go", as other Objects may be effected. So those things are best left to a Function or Method, ( a .Add or .Insert , for example ). There will always be arguments associated and require them ( if you ,leave them about, VBA at compile will try to guess ( based on other available information and / or arguments), what you want, or always using a particular default when you omit an argument )


    So my original suggestion of an additional implicitly defaulted
    Set ws = New Worksheet
    Before
    Set ws = Worksheets(“Sheet1”)
    Was a load of old bollox. The two things are alternatives. Without New, we are not instancing. In both cases we are assigning to an Object. For the New that Object has yet to be built, but the New virgin copy of the Blue print will be reference by the variable ws. For without New we have a final Object, ( but can lightly change it or indeed instance that indirectly through a Method. In such a case we will have an Instance and an additional ( so “new” ) one at that! It is not a virgin of the Class.

    So generally
    Set ___ = New ____ means virgin and we can usually create such an instance
    And
    Set __ = ____ means not virgin and an option for instancing directly will not be given usually.
    _.....................

    _2 ) ByRef ByValue stuff...
    I did some notes for myself on this "can of worms" some time ago to save time when answering Threads on this Theme. I have not been able to advance much on those explanations, but based on the comments here in this Thread I have just made some minor alterations. I will not repeat them again here !
    Here they are.


    http://www.excelforum.com/showthread...t=#post4381274
    http://www.excelforum.com/showthread...t=#post4381275
    http://www.excelforum.com/showthread...t=#post4381420

    _...............................

    Thanks again everyone
    Alan
    Last edited by DocAElstein; 06-07-2024 at 01:49 PM.

Similar Threads

  1. Class related Stuff Userforms
    By DocAElstein in forum Test Area
    Replies: 29
    Last Post: 06-08-2024, 01:22 PM
  2. Class Stuff: VBA Custom Classes & Objects, Class Modules
    By DocAElstein in forum Excel and VBA Tips and Tricks
    Replies: 29
    Last Post: 06-02-2024, 01:49 PM
  3. Replies: 42
    Last Post: 05-29-2023, 01:19 PM
  4. Gif Image Video stuff testies
    By DocAElstein in forum Test Area
    Replies: 13
    Last Post: 09-06-2021, 01:07 PM
  5. Test my rights , to do stuff
    By TestAccount in forum Test Area
    Replies: 0
    Last Post: 10-07-2020, 11:49 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •