Page 2 of 3

Re: Data objects

Posted: Mon Jan 30, 2023 7:39 pm
by mwieder
but of course we are limited to the predefined ones.
Yep - I think that's where the analogy falls down.

Re: Data objects

Posted: Mon Jan 30, 2023 9:19 pm
by dunbarx
Just as I have been building things for 36 years.

But again, can widgets be the new "object class", er, object class?

Craig

Re: Data objects

Posted: Tue Jan 31, 2023 1:37 am
by stam
Craig makes a good point. If I'm not mistaken we should soon be able to constructs 'widgets' directly in LC, this seems to fill that brief...

Re: Data objects

Posted: Tue Jan 31, 2023 3:02 am
by mwieder
Widgets would also be in much the same category as the built-in objects in as much as a set of pushButton controls would all act similarly, given the properties and functions of the base pushButton widget.

But where some of the real power of classes comes in is that modifications to the original object will affect any of the child objects. And that's part of where the analogy to object-oriented programming falls apart, because we can't modify a generic field object in ways that will affect fields based on it (and we'd be in serious trouble in LiveCodeLand if that were so). And I think that's where the power of behaviors comes into play.

More class-like functionality can come from (for instance) creating a group of buttons, pointing them all to a common behavior script, and then changes to the behavior script later on will affect the entire "class" of buttons that are linked to it. In any event this will all be somewhat imperfect because we're trying to graft object-oriented programming onto an environment that doesn't natively support it.

Re: Data objects

Posted: Tue Jan 31, 2023 1:29 pm
by richmond62
Why can we not clone a template field object, rename it, and then muck around with it to create a new object?

Re: Data objects

Posted: Tue Jan 31, 2023 3:02 pm
by dunbarx
Richmond.

How does that create a new object class? The templateWhatevers are terrific gadgets, but they only preset one or more properties of the object class they designate. They are wonderful shortcuts, not anything new.

Craig

Re: Data objects

Posted: Tue Jan 31, 2023 5:23 pm
by mwieder
Yes, Craig nailed it. The template objects only act as sort-of classes at the time of creating new objects.
You can't create new custom properties of template objects and you can't add new handlers to them - you can only act on a predefined list of properties. And maybe more importantly, if you change a property of a templateField it doesn't affect any existing fields, just the ones you create afterwards.

That's where behaviors can come in handy as another kins of sort-of classes.
If you create a bunch of fields and you want to add a foo() function to one you modify its script.
But if you want all of them to have the foo() function you could just modify the behavior script they all have in common.

If you have a lot of those fields this not only saves a lot of effort, but if you make a mistake you only have to correct it once. <g>

Re: Data objects

Posted: Tue Jan 31, 2023 5:39 pm
by FourthWorld
Not all languages are OOPs.

In this non-OOP language, would this request for automated data handling not bound to specific UI elements be implementable with a library that creates and manages specific arrays as though they're structs?

Re: Data objects

Posted: Tue Jan 31, 2023 5:52 pm
by mwieder
Well, this is LiveCode, so anything's possible, no?

I still think I'd use a database for the OP's person object, but...

would placing getprop and setprop handlers in a behavior script do the proper data binding for that?

Re: Data objects

Posted: Tue Jan 31, 2023 6:57 pm
by dunbarx
Mark.
You can't create new custom properties of template objects
You can, though. Custom properties are just properties. They do not survive sessions, though.

Craig

Re: Data objects

Posted: Tue Jan 31, 2023 7:03 pm
by mwieder
Hah! I had tried this before posting that message and it didn't work, now it does.

Re: Data objects

Posted: Tue Jan 31, 2023 7:04 pm
by dunbarx
More trivia.

If I

Code: Select all

set the height of the templateButton to 100
set the XYZ of the templatebutton to "123"
and then create a new button by pulling from the tools palette, the custom property sticks, but not the height. But if I

Code: Select all

create button
both stick.

Craig

Re: Data objects

Posted: Tue Jan 31, 2023 7:06 pm
by dunbarx
Mark.
Hah! I had tried this before posting that message and it didn't work, now it does.
What do you mean??? Are you saying that there are evil spirits lurking in LC, or in our minds, or both???????

????????????

Craig

Re: Data objects

Posted: Tue Jan 31, 2023 7:09 pm
by mwieder
Yep - it's obvious that your post was the magic incantation that got things working.
I'll keep you in mind for the next time some of my code doesn't work.

Re: Data objects

Posted: Tue Jan 31, 2023 7:36 pm
by FourthWorld
mwieder wrote: Tue Jan 31, 2023 5:52 pm I still think I'd use a database for the OP's person object
I wonder if Trevor's SQLYoga would be a good fit here. It treats data connectors as property -driven virtual objects.

https://github.com/trevordevore/sql-yoga/wiki