DataObject()

86 views
Skip to first unread message

Maurilio Longo

unread,
Sep 29, 2022, 2:17:23 AM9/29/22
to harbou...@googlegroups.com
Hi all,

it's been a long time since I last wrote here, I hope all is well for everybody!

Now, in the last few days I did try to develop something that, on the surface,
is very simple, a class where member variables are added at runtime only.

This is to "emulate" the DataObject class of xbase++, which is just a
container for data with an OOP syntax.

https://doc.alaska-software.com/content/cls_xppcref_dataobject.html

Reading src\vm\classes.c and tests\dynobj.prg I've realized that the code
available in classes.c and used by dynobj.prg adds member variables (and
methods) to a class definition and not to an already instantiated object.

This creates the "problem" that each new object I instantiate from such a
class already has all the previously added member variables, which is not what
I want or need: think about serializing such an object or having two different
objects with a method with the same name but different behaviour.

I could create a new class definition for each instance of this kind of
objects that I need, but there is no way to remove a class definition when
there is no more need for it.
This would, overtime, cause a kind of memory leak due to class definitions
that add up which won't be used anymore and, btw, I can't remove the class
even if there is a function called hb_classRelease() in classes.c, but it is
there for cleaning up everything when the application ends and not for
managing class definitions at runtime.

So, I'd like to know your opinion on this matter and on the feasibility of
adding member variables/methods to instances of a class and not to a class
definition itself which is something a little bit out of my remaining memories
of the inner workings of Harbour and, btw, maybe I'm just wrong or unaware
that there is a way to do what I'm trying to do.

Thanks and best regards.

Maurilio.

--
__________
| | | |__| Maurilio Longo
|_|_|_|____|

Lorenzo Fiorini

unread,
Sep 29, 2022, 3:26:07 AM9/29/22
to harbou...@googlegroups.com
Hi Maurilio, it’s so good to have you here again.

Lorenzo Fiorini

> On 29 Sep 2022, at 08:17, 'Maurilio Longo' via Harbour Developers <harbou...@googlegroups.com> wrote:
>
> Hi all,
> --
> You received this message because you are subscribed to the Google Groups "Harbour Developers" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to harbour-deve...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/harbour-devel/6335467A.6080000%40libero.it.

José F. Giménez

unread,
Sep 29, 2022, 3:38:01 AM9/29/22
to harbou...@googlegroups.com
Hi,

you may use a simple and basic class implementing the "ERROR HANDLER"
feature to catch any message sent to the object. ITOS, you may store any
variable in a hash handled by the own class.

Regards,

Jose F. Gimenez
http://www.xailer.com

maurili...@libero.it

unread,
Sep 29, 2022, 3:47:33 AM9/29/22
to harbou...@googlegroups.com
Thank you Lorenzo,

I've never really left, I was just lurking ;)

Regards.

Maurilio
> To view this discussion on the web visit https://groups.google.com/d/msgid/harbour-devel/3212BC8A-FEF7-4249-97DA-5A8AFDB4A975%40gmail.com.

maurili...@libero.it

unread,
Sep 29, 2022, 3:49:53 AM9/29/22
to harbou...@googlegroups.com, José F. Giménez
Hi José,

yes, I'm using the error handler to add the member variables right now, but using it to access data stored somewhere inside the objet incurs the penalty of a call to the error handler for each access.

Think about a loop...

Regards.
Maurilio.
> --
> You received this message because you are subscribed to the Google Groups "Harbour Developers" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to harbour-deve...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/harbour-devel/444dce35-0f59-447a-bb36-d9b16d07d69e%40xailer.com.
Reply all
Reply to author
Forward
0 new messages