comp.lang.idl-pvwave archive - RDF feed
type: channel
description: Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado
items: Copying (cloning) objects -- Testers wanted

Copying (cloning) objects -- Testers wanted
type: item
description: Hi, this is more and more fun! Please find attached a base object definition which contains a few useful features that you can nicely inherit in anything else: The object contains a NAME and a UVALUE field which can be set with the Init method (where NAME must be a string and UVALUE can be anything). It contains a method for displaying an error message either as a dialog box or on the log screen (controlled by the no_dialog keyword), and -- and this I am most proud of -- it contains a method for duplicating itself. And this works for any object that inherits from it. Thanks to James Tappin who gave me the idea to create a structure with the object fields ( stru = { object } ), and to JD Smith who had the Struct_Assign idea. What the Copy() method does is to create a copy of self as simply as ;; Initialize an empty object of the same type as self clone = Obj_New( Obj_Class(self) ) ;; Do a structure assignment to copy all fields verbatim Struct_Assign, self, clone, verbose=verbose But that leaves you with the problem that pointers and object references in the new object still point to the data and objects from the old object. So I apply James' trick with a little variant: ok = Execute('ostru = {'+Obj_Class(self)+'}') in order to get a structure equivalent of the current object. Then I loop through the structure tags and whenever there is a pointer, I call a method CopyPointers which does just what it says (took me a while to avoid the traps of pointer arrays and pointers pointing to object references, but it is still remarkably short, I think). Object references are handled by calling the Copy method of the referenced object. You can control some of this with keywords (no_pointers, no_objects, free_pointers, or free_objects). The code is heavily documented, so there is hope even if you don't understand what I was talking about here ;-) In order to use the base object in a meaningful way, you should inherit from it. To show you how this is done, I also attach a class n…
creator: Martin Schultz
date: 2000-06-09T07:00:00-00:00