Big problem [solved]

Is it possible to make a class that behaves like a data type in Xojo? (I’ve seen this question asked before, but haven’t seen it answered very well.)

Here’s my problem: I have been using Bob Delaney’s Decimal plugin for an app I’ve been developing for the past year. I’ve found however that this plugin has problems, the worst of which is that it leaks memory like a sieve. Version 3.6 was supposed to stop memory leaks, but it doesn’t. So I have lots of properties set to the Decimal data type, which were originally Double before I started using the plugin. To stop using the plugin, I will have to change all of the Decimal types back to Double. The problem with this is, after I do that, I can’t ever go back, because although I can search and replace Decimal with Double, there will be no way after that to search and replace Double with Decimal, since there are countless places in the code where Double is used already, where I do NOT want to use Decimal. So my idea is to get rid of the plugin and make my own class called Decimal which behaves the same way but is just a Double under the hood. Then if the plugin ever gets fixed, I can remove my class and install the plugin again without having to change my code.

Or does anyone have other advice for dealing with this problem? Thanks in advance.

So exactly what is your question.

Yes you can create a class … and that class can contain properties and methods…

what it would take to “behave like the plugin” would be something you’d have to determine

and “technically” a class IS a custom datatype… . many of Xojo datatypes are “classes”… Folderitem, even String

I remember about Decimal plugin and memory leaks. After Bob released 3.6 I used the same test/tool that someone posted in the forum and I was not able to detect a leak (for a simple test), that make a huge difference (on that simple test). Did at least 3.6 reduced the memory leaks on your program? Or could the leaks be from something else?

I found a simple solution. Xojo allows case-sensitive search and replace. So I searched and replaced all instances of Decimal with DoUbLe to distinguish all those instances as former Decimal properties. Later I can do a case-sensitive search and replace only on those instances without changing all the other doubles.

Just don’t accidently do a “Standardize Format” command, or you’re “screwed”

Speaking of which, I wish “Standardize Format” changed the case of my own code to what it should be. I am as lazy respecting my own camelCase than I am obsessive about it being “wrong” afterwards.

Since the IDE knows what my methods and variables are, it could “fix” them just as it would if I “tabbed” them.

You can customize it with a XojoScript in just the right place in your Documents folder. I don’t have the specifics, but it can be done.

In answer to your question, yes I believe it should be possible. To get it working you’d need to implement some or all of the following operator overloads.

I want to mention with apologies to Bob Delaney and repeated thanks for his plugin, that the memory leak which appears to come from the plugin is in fact very small. (I would edit the initial post to correct what I said there, but the system won’t let me do it.) A much larger leak was coming from a different place and it only looked like it was the decimal plugin. In any case, the technique of case-sensitive search-replace allowed me to remove the plugin and test further in order to find and fix the bigger leak, and then put the plugin back in. Anyone else ever spend a whole day finding and fixing memory leaks? Fun stuff!