[英]UnicodeString Delete Method (different result between 32-bit Win and iOS/Android)
I'm building a simple FMX app in C++ Builder (Tokyo 10.2.3) that displays agenda data from an SQLite db. 我正在C ++ Builder(Tokyo 10.2.3)中构建一个简单的FMX应用程序,该应用程序显示来自SQLite数据库的议程数据。 I've added a
TComboBox
to let the user filter what is presented. 我添加了一个
TComboBox
以便用户过滤显示的内容。 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. 我正在使用组合框向数据库上的SQL查询添加过滤器。 The data set has a field
committee
and each row of data belongs to one of those 3 committees (PSSC, TD, RRMS). 数据集有一个现场
committee
,每一行数据都属于这三个委员会之一(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.
它可以在32位Windows上正常运行,但不能在iOS或Android上运行。 All I'm doing is trimming off the
"Show "
with the .Delete
to the UnicodeString mystring
. 我正在做的就是用
.Delete
修剪掉"Show "
到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. 这就是正在发生的情况,在32位Windows中,
mystring
确实应有。 If i select "Show PSCC" from the combobox, then mystring
ends up "PSCC" and the query works great. 如果我从组合框中选择“显示PSCC”,则
mystring
结尾为“ PSCC”,查询效果很好。 But, when I run on iOS or Android mystring
ends up "SSCC". 但是,当我在iOS或Android上运行时,
mystring
最终为“ SSCC”。 The first letter of whatever is selected becomes an S. I can't for the life of me figure out why. 无论选择什么,首字母都会变成S。我一生都无法弄清楚为什么。
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. 我发帖是因为我只是好奇这个“ S”在iOS或Android而不是32位Win上的原始代码中如何显示。
ps Just using TFDConnection
, TFDQuery
, and FDPhysSQLiteDriverLink
on my Firemonkey form. ps仅在Firemonkey表单上使用
TFDConnection
, TFDQuery
和FDPhysSQLiteDriverLink
。
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. 因此,似乎在编译器中有所不同,移动编译器(iOS / Android)的索引从0开始,桌面编译器(Windows / OSX)的索引从1开始。感谢GSerg指出了这一点。
Here is a solution that explicitly uses 0-indexing for all platforms. 这是一个明确为所有平台使用0索引的解决方案。 The only changes are the
0
you see added to the end of .Delete
and also inside the parenthesis: 唯一的变化是
0
,你看到添加到年底.Delete
并在括号内:
mystring = mystring.Delete0(0, 5);
This code works the same on Windows, iOS, and Android. 此代码在Windows,iOS和Android上的工作原理相同。 Thanks to an old post from Remy: UnicodeString::Delete Method
感谢Remy的一篇旧文章: UnicodeString :: Delete方法
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.