Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2013-10

About TComboBox.Items.IndexOfName

11 messages · 6 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

FreeMan

Hello,
I'm not sure is this bug? can some one test please? and if its but I'll make new issue.
I have a TComboBox, I add 2 strings. I wanna do, if TmpStr is in the items, do it selected.

   I := EDT_User.Items.IndexOfName(TmpStr);
   EDT_User.ItemIndex:= I;

1-) I is always return -1;
2-) I add breakpoint on IndexOfName function, debugger stop there, when click F7 not to go that function, I added breakpoint in IndexOfName function, but never stop in, directly jump to next line on my code. 3-) EDT_User.ItemIndex:= 1; this code not to trigger Text property, text not change

/opt/freepascal/2.7.1/rtl/objpas/classes/stringl.inc line 784

Kubuntu 13.10 x64
fpc svn update 25886
lazarus svn update 43343
QT

FreeMan
to FreeMan

Sorry
3-) EDT_User.ItemIndex:= 1; this code not to trigger Text property, text not change
my mistake. This code work correctly, many code for test and my carelessness
1. and 2. still problem on my system

30-10-2013 23:41 tarihinde, FreeMan yazd?:

Show quoted text 30 lines
Hello, I'm not sure is this bug? can some one test please? and if its but I'll make new issue. I have a TComboBox, I add 2 strings. I wanna do, if TmpStr is in the items, do it selected. I := EDT_User.Items.IndexOfName(TmpStr); EDT_User.ItemIndex:= I; 1-) I is always return -1; 2-) I add breakpoint on IndexOfName function, debugger stop there, when click F7 not to go that function, I added breakpoint in IndexOfName function, but never stop in, directly jump to next line on my code. 3-) EDT_User.ItemIndex:= 1; this code not to trigger Text property, text not change /opt/freepascal/2.7.1/rtl/objpas/classes/stringl.inc line 784 Kubuntu 13.10 x64 fpc svn update 25886 lazarus svn update 43343 QT -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Martin
to FreeMan
FreeMan wrote 5 lines
> 2-) I add breakpoint on IndexOfName function, debugger stop there, > when click F7 not to go that function, I added breakpoint in > IndexOfName function, but never stop in, directly jump to next line > on my code.

For debugging, recompile LCL and LCLbase with debug info.

Open each package, and change options

Mattias Gaertner
to FreeMan: I'm not sure is this bug? can some one test please? and if its but I'll make new issue. I…
Show quoted text 7 lines
Hello, I'm not sure is this bug? can some one test please? and if its but I'll make new issue. I have a TComboBox, I add 2 strings. I wanna do, if TmpStr is in the items, do it selected. I := EDT_User.Items.IndexOfName(TmpStr);

When you press F1 for help you get:

http://lazarus-ccr.sourceforge.net/docs/rtl/classes/tstrings.indexofname.html

Mattias

zeljko
to FreeMan: I'm not sure is this bug? can some one test please? and if its but I'll make new issue. I…
FreeMan wrote 22 lines
Hello, I'm not sure is this bug? can some one test please? and if its but I'll make new issue. I have a TComboBox, I add 2 strings. I wanna do, if TmpStr is in the items, do it selected. I := EDT_User.Items.IndexOfName(TmpStr); EDT_User.ItemIndex:= I; 1-) I is always return -1; 2-) I add breakpoint on IndexOfName function, debugger stop there, when click F7 not to go that function, I added breakpoint in IndexOfName function, but never stop in, directly jump to next line on my code. 3-) EDT_User.ItemIndex:= 1; this code not to trigger Text property, text not change /opt/freepascal/2.7.1/rtl/objpas/classes/stringl.inc line 784 Kubuntu 13.10 x64 fpc svn update 25886 lazarus svn update 43343 QT

That's probably 2.7.1 problem. With 2.6.2 it works ok. Also, if it's because of qt , look into lcl/interfaces/qt/qtprivate.pp where we define TStrings for combobox, maybe some tuning for 2.7.1 is needed there.

z.

Antonio Fortuny
to FreeMan: I'm not sure is this bug? can some one test please? and if its but I'll make new issue. I…

Le 30/10/2013 22:41, FreeMan a ?crit :

Show quoted text 10 lines
Hello, I'm not sure is this bug? can some one test please? and if its but I'll make new issue. I have a TComboBox, I add 2 strings. I wanna do, if TmpStr is in the items, do it selected. I := EDT_User.Items.IndexOfName(TmpStr); EDT_User.ItemIndex:= I; 1-) I is always return -1;

Well, I don't know what's in the Items property (TStrings) but if I execute a
Index := Combo.Iyems.IndexOf('My text');

I receive 7 when the string 'My text' is in the 8th position, counting from 1.
When the Items property contains
one=1
two=2
three=3
four=4
doing:

   str := 'three';
   Index := ComboBox1.Items.IndexOfName(str);
   str2 := ComboBox1.Items.Values[str];
   MessageDlg('Search',Format('index:%d, val:%s', [Index, str2]),

mtInformation, [mbOK], 0, mbOK);
result is 'index:2 val:3

platform is Vista32, Lazarus 1.0.12

Antonio.

Show quoted text 20 lines
2-) I add breakpoint on IndexOfName function, debugger stop there, when click F7 not to go that function, I added breakpoint in IndexOfName function, but never stop in, directly jump to next line on my code. 3-) EDT_User.ItemIndex:= 1; this code not to trigger Text property, text not change /opt/freepascal/2.7.1/rtl/objpas/classes/stringl.inc line 784 Kubuntu 13.10 x64 fpc svn update 25886 lazarus svn update 43343 QT -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
FreeMan
to Antonio Fortuny

Hello Antonio,
Thank for test, In your code is okey, index is start 0 zero so, you write one but it's index number is 0.
So, -1 is not selected or no value or index mean
My system has problem, I thing. Other friends wrote some info, I'll check and I'll write to list
Thank to all

31-10-2013 09:56 tarihinde, Antonio Fortuny yazd?:

Show quoted text 65 lines
Le 30/10/2013 22:41, FreeMan a ?crit : > Hello, > I'm not sure is this bug? can some one test please? and if its but > I'll make new issue. > I have a TComboBox, I add 2 strings. I wanna do, if TmpStr is in the > items, do it selected. > > I := EDT_User.Items.IndexOfName(TmpStr); > EDT_User.ItemIndex:= I; > > 1-) I is always return -1; Well, I don't know what's in the Items property (TStrings) but if I execute a Index := Combo.Iyems.IndexOf('My text'); I receive 7 when the string 'My text' is in the 8th position, counting from 1. When the Items property contains one=1 two=2 three=3 four=4 doing: str := 'three'; Index := ComboBox1.Items.IndexOfName(str); str2 := ComboBox1.Items.Values[str]; MessageDlg('Search',Format('index:%d, val:%s', [Index, str2]), mtInformation, [mbOK], 0, mbOK); result is 'index:2 val:3 platform is Vista32, Lazarus 1.0.12 Antonio. > 2-) I add breakpoint on IndexOfName function, debugger stop there, > when click F7 not to go that function, I added breakpoint in > IndexOfName function, but never stop in, directly jump to next line > on my code. > 3-) EDT_User.ItemIndex:= 1; this code not to trigger Text property, > text not change > > /opt/freepascal/2.7.1/rtl/objpas/classes/stringl.inc line 784 > > Kubuntu 13.10 x64 > fpc svn update 25886 > lazarus svn update 43343 > QT > > -- > _______________________________________________ > Lazarus mailing list > > http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus > -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Sven Barth
to FreeMan: I'm not sure is this bug? can some one test please? and if its but I'll make new issue. I…
FreeMan wrote 10 lines
Hello, I'm not sure is this bug? can some one test please? and if its but I'll make new issue. I have a TComboBox, I add 2 strings. I wanna do, if TmpStr is in the items, do it selected. I := EDT_User.Items.IndexOfName(TmpStr); EDT_User.ItemIndex:= I; 1-) I is always return -1;

Does your combobox contain non-ASCII characters? How is TmpStr declared?

Regards,
Sven

FreeMan
to Sven Barth

No any non-ASCII characters,
'Admin', 'xxxxx' this to strings added in items
TmpStr:= 'Admin'
I := EDT_User.Items.IndexOfName(TmpStr);
or
I := EDT_User.Items.IndexOfName('Admin');
same result

31-10-2013 11:51 tarihinde, Sven Barth yazd?:

Show quoted text 22 lines
Am 30.10.2013 22:41, schrieb FreeMan: > Hello, > I'm not sure is this bug? can some one test please? and if its but > I'll make new issue. > I have a TComboBox, I add 2 strings. I wanna do, if TmpStr is in the > items, do it selected. > > I := EDT_User.Items.IndexOfName(TmpStr); > EDT_User.ItemIndex:= I; > > 1-) I is always return -1; Does your combobox contain non-ASCII characters? How is TmpStr declared? Regards, Sven -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Sven Barth
to FreeMan
FreeMan wrote 8 lines
No any non-ASCII characters, 'Admin', 'xxxxx' this to strings added in items TmpStr:= 'Admin' I := EDT_User.Items.IndexOfName(TmpStr); or I := EDT_User.Items.IndexOfName('Admin'); same result

Ah, wait. Now I get your problem. You need to use "IndexOf" instead of "IndexOfName". The latter is for cases where the TStrings instance contains name-value pairs (like "Foobar=blubb") whereby this will return the index of the name-value pair with name "Foobar". For your case you need to use "IndexOf" which checks the complete string.

Regards,
Sven

FreeMan
to Sven Barth

Thank you very much Sven,
IndexOf function work correctly

31-10-2013 12:01 tarihinde, Sven Barth yazd?:

Show quoted text 24 lines
Am 31.10.2013 10:56, schrieb FreeMan: > No any non-ASCII characters, > 'Admin', 'xxxxx' this to strings added in items > TmpStr:= 'Admin' > I := EDT_User.Items.IndexOfName(TmpStr); > or > I := EDT_User.Items.IndexOfName('Admin'); > same result > Ah, wait. Now I get your problem. You need to use "IndexOf" instead of "IndexOfName". The latter is for cases where the TStrings instance contains name-value pairs (like "Foobar=blubb") whereby this will return the index of the name-value pair with name "Foobar". For your case you need to use "IndexOf" which checks the complete string. Regards, Sven -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus