Fixing code by not touching it follow up

In the case I described the code is in a subclass a Xojo class

The idea here is to INSERT a new subclass between the existing subclass and the new one. And the newly inserted subclass will expose things in a way the OLD existing code wont break

So we never touch the old code
We just modify the inheritance chain in a way we can then alter how things behave

So in his case we can add a new subclass of EmailMessage that exposes the Source as a Method pair ( get & set) and then make the existing class inherit from our new class

And the existing code will then JUST work without ever having had to alter any of it

Next time you have an issue like this consider that as an option !

Fixing code by not touching it

The other day I was helping a friend with some code that worked fine in several versions of Xojo but then in a newer one wouldn’t compile

Seems he found a compiler regression Whether this _should_ have been caught by regression tests etc is an entirely different question.

It exists. And now his large project doesn’t compile.… Read the rest

Tired of adding strings ?

If you’ve ever had to write a lot of output with strings you’ve probably had to concatenate them.

In VB you used &. In Xojo you use + and more than likely Str, Format, and the newer ToString.

Eventually when you write enough code you end up with things that look like

Var Explanation as string = "Hint: If you don't save," _
  + " you will lose your work" _
  + " since your last Save."
Read the rest

Operator_Convert

Operator_Convert is a very handy method to implement on a lot of classes. It not only lets you create a mechanism to make your classes convert themselves into other types but it also lets you create new instances FROM other data types.

So let’s start with the simple forms of operator_convert – the “convert TO” forms.… Read the rest

Downgrade 2019.R2 to 2019.R1.1

It had to happen sooner or later. But now questions about how to do this are appearing. And the answer is “it depends”.

ALWAYS use a copy or have a backup copy of your entire project JUST in case something goes wrong.

IF you have a license that permits you to save as text (Xojo Project) save your project as a text project.… Read the rest

Prepared Statements

Often you’ll hear people say you should use prepared statements to avoid sql injection issues. They’re not wrong. But there can be other reasons to use them.

In some db’s when you create a prepared statement and use it over & over you can avoid a fair amount of a speed hit.

When you initially create a prepared statement many db engines will actually do some work to figure out what the optimal mechanism, or query plan, is to access the data in a table.… Read the rest

Extension methods

Sometimes you run into a situation where you want to add functionality to an existing data type. It might be a string, integer, array or perhaps one of the built in classes that you want to add new functionality to.

Exactly how do you do this ?

You can’t just edit the framework and add new methods to the String type.… Read the rest

Moving to 2019r2

2019r2 changes a LOT of things.

Some of the things it changed are subtle and search and replace may NOT be the best approach to updating these.

For instance string method like Mid changed from being a 1 based offset for the starting position to a 0 based offset.

If all you do is change mid to middle you will inadvertently cause an off by one error because the start is now 0 based not 1 based.… Read the rest

Spot the bug

You might run into this one from time to time. I know it has bitten a LOT of people and it’s not intuitive at all.

In a new desktop app add a new Class. The default name of Class1 will work fine. And create a new subclass of this. Again the default of CustomClass1 will work fine.… Read the rest