Jump to content
kidego9436

OutOfRange Error with TComboEdit in Delphi FMX

Recommended Posts

Hello everyone,

I've encountered an "List index out of bounds (0). TStringList is empty."-bug in my Delphi (FMX) application when executing the following code for a ComboEdit:

//Prepare the ComboEdit:
ComboEdit1.Items.Clear;
ComboEdit1.Items.Add('A');
ComboEdit1.ItemIndex := 1;

//Do Stuff...

//Change the Content later again:
ComboEdit1.Items.Clear;
ComboEdit1.Text := 'B';

It seems that the error originates from the "TComboEditModel.DoValidate(const Value: string);"-method in the "FMX.ComboEdit.pas"-file. 

In line 446 is an "if" that causes the exception:
 

if (ItemIndex <> -1) and (Text <> Items[ItemIndex]) then

"ItemIndex" has the Value "0" in the debugger.

My Workaround would be to add a "ItemIndex := -1" to my Code, but thats some kind of ugly to add it everywhere:

//Prepare the ComboEdit:
ComboEdit1.Items.Clear;
ComboEdit1.Items.Add('A');
ComboEdit1.ItemIndex := 1;

//Do Stuff...

//Change the Content later again:
ComboEdit1.Items.Clear;
ComboEdit1.ItemIndex := -1;
ComboEdit1.Text := 'B';


 

Share this post


Link to post

The first Item of a list (ITEMS -> ItemIndex) is ZERO not ONE.

 

17 minutes ago, kidego9436 said:

ComboEdit1.Items.Clear; ComboEdit1.Items.Add('A'); ComboEdit1.ItemIndex := 1;

ComboEdit1.Items.Clear;
ComboEdit1.Items.Add('A');
ComboEdit1.ItemIndex := 0;   <---------- SHOULD BE 0

 

Share this post


Link to post

He is on something there…

i noticed the same issue in one of my projects.

 

Change the first itemindex to 0 and try it again.

The exception raises while setting the text property in the rtl.

Share this post


Link to post
1 hour ago, jakicex571 said:

The exception raises while setting the text property in the rtl.

I confirm the behaviour

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×