Deprecated replacement

XOJO 2020r2.1 - Windows 10 Desktop

Following line of code was used before :
DataList.CellValueAt(row, kColCommand) = Mid(HP_TypeName(Val(DataList.CellValueAt(row, 7))), 4).Lowercase.ReplaceAll("", " “).Titlecase
Mid is deprecated and I should use Middle instead:
DataList.CellValueAt(row, kColCommand) = HP_TypeName(Val(DataList.CellValueAt(row, 7))).Middle(4).Lowercase.ReplaceAll(”
", " ").Titlecase
But this gives an error !

I changed the line by two lines and then it works :
s = HP_TypeName(Val(DataList.CellValueAt(row, 7)))
DataList.CellValueAt(row, kColCommand) = s.Middle(4).Lowercase.ReplaceAll("_", " ").Titlecase

Why doesn’t it work anymore with one line of code as i did before ?

Regards
Etienne

Please refactor your code into multiple lines. That way you can figure out yourself what is going wrong.

3 Likes

Be warned that even though the code compiles, it still isn’t right.

As for why it must be two lines, I’m guessing HP_TypeName returns a Variant instead of String.

I don’t analyse all the code but you have Mid(4) replacing by Middle(4) . Be carrefull, it should be .Middle(3) as Mid consider first character at 1 when the first character is 0 for Middle .

1 Like

Thanks for the replies.
@Thomas : thanks for the tip.
I need to be attentive with my upgrade to XOJO 2020r2.1
Are there more items that changed from 1-based to 0-based ?
Is there somewhere a list ?

Regards
Etienne

Are there more items that changed from 1-based to 0-based ?
All

Is there somewhere a list ?
API2

InStr was 1 based and is replaced by Text.IndexOf which is 0 based.

With Mid and Middle, they are the 2 instructions which caused me the most work to update from API1 to API2. Maybe they are other instructions.

Ok, but the change from 1-to 0-based will always be due to a command change ?
Mid changes to middle
Instr changes to IndexOf

If the command stays the same there will be no change to 0-based ?
For example : NthField does not change, Left and Right do not change …

Is this correct ?

Yes, fortunately, our applications would have became very buggy if they changed the way instructions work without change their name.
Then to be clear, if you don’t change anything, all will work as before until Xojo deprecated the API1 instructions. But they explained it will be in a very long time (without telling what is a very long time).

Thanks for the reply.
Regards

Other culprit: if some API1 stop working in a new OS or a new hardware, then I suspect that “a very long time” have come.

When I read “a very long time” I understand “if you never upgrade either software / hardware”.

Why ? It is in the word “deprecated” and in the business: who update a “years ago“ version ? (when the current one works fine).

http://documentation.xojo.com/api/data_types/string.html#string-middle

says:

The first character position is 0.

There is a bunch of files that talks about API2. Examples:
http://documentation.xojo.com/topics/api_design/moving_to_api_2.0.html

http://documentation.xojo.com/UserGuide:API_2.0_Guidelines#User_Interface_Controls

do not found a page in the docs where they talks about every control start at 0; no more asking yourself if this is 0 or 1: the first index will always be 0.

That is what I wanted to say above (with far fewer words).

Left and Right takes a parameter for a length and NthField hasn’t suffered from that change.
The 0-based vs 1-based change is about indexes.

FWIW, I believe the examples of converting Joe Strouts libraries might help you a bit, as you can compare the old code with the new one. Overall the transition isn’t too complicated. 2 difficulties I saw:

  • Discipline to adhere to API2 everywhere in your code
  • Having to work with an older Xojo Version w/o API2 turns out to be “difficult” after a few weeks :wink:
1 Like

Indeed, I started a new app in XOJO 2020r2.1 (API2).
When I returned working on my app in XOJO 2018r4 this was very “strange / difficult”.
That’s the reason why I started migrating my XOJO 2018r4 app to XOJO 2020r2.1.

As far as I could test, the app was directly working in XOJO 2020r2.1.
Now I like to solve all the “Deprecated” items.
A lot of work, but little by little …

Regards

1 Like

Not everyone will agree, but I think you made the right choice. I just don’t want to bother with too many “dialects” of one language :wink: