UnicodeString Delete Method (different result between 32-bit Win and iOS/Android)

114 views Asked by At

I'm building a simple FMX app in C++ Builder (Tokyo 10.2.3) that displays agenda data from an SQLite db. I've added a TComboBox to let the user filter what is presented. The combo box has the following items added to it at runtime (these are committee names):

Show PSSC
Show TD
Show RRMS

I'm using the combo box to add a filter to an SQL query on the database. The data set has a field committee and each row of data belongs to one of those 3 committees (PSSC, TD, RRMS).

Below is my code to add the filter into a query. It works fine on 32-bit Windows but not on iOS or Android. All I'm doing is trimming off the "Show " with the .Delete to the UnicodeString mystring.

mystring = Form1->cmbBoxFilters->Selected->Text;
mystring = mystring.Delete(1, 5);
query->SQL->Text = "SELECT * FROM mtgs WHERE weekday = '" + myday + "' AND committee = '" + mystring + "'";

Here is what is happening, in 32-bit Windows mystring is exactly as it should be. If i select "Show PSCC" from the combobox, then mystring ends up "PSCC" and the query works great. But, when I run on iOS or Android mystring ends up "SSCC". The first letter of whatever is selected becomes an S. I can't for the life of me figure out why.

I'm posting because I'm just curious as to how this "S" is showing up in my original code on iOS or Android and not 32-bit Win.

p.s. Just using TFDConnection, TFDQuery, and FDPhysSQLiteDriverLink on my Firemonkey form.

1

There are 1 answers

3
relayman357 On BEST ANSWER

So, it looks like a difference in the compilers, with mobile compilers (iOS/Android) indexing from 0 and desktop compilers (Windows/OSX) indexing from 1. Thanks to GSerg for pointing that out.

Here is a solution that explicitly uses 0-indexing for all platforms. The only changes are the 0 you see added to the end of .Delete and also inside the parenthesis:

mystring = mystring.Delete0(0, 5);

This code works the same on Windows, iOS, and Android. Thanks to an old post from Remy: UnicodeString::Delete Method