title: Error in adding objects to a TListBox?
body: <p>An apparently attractive feature of FMX is adding visual objects to a TListBox. In a previous question I mentioned the trouble of <a href="https://stackoverflow.com/questions/19960267/trouble-synchronizing-generic-tlist-and-tlistbox/19998855#19998855">correctly positioning objects inside the TListBox</a>. An additional annoyance I discovered is using InsertObject. When 8 objects are added to a TListBox I get "Argument out of range". On Android I can get this error message when adding the 2nd object. I could isolate this problem in a small program:</p>
  
  <pre><code>  unit tlist_item;
  
    interface
  
    uses
      System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
      FMX.Types, FMX.Graphics, FMX.Controls, FMX.Forms, FMX.Dialogs, FMX.StdCtrls;
  
    type
       TItem_Frame = class(TFrame)
        Button1: TButton;
        Label1: TLabel;
        SpeedButton1: TSpeedButton;
  
        procedure SpeedButton1Click (Sender: TObject);
  
       public
          FOnInsert: TNotifyEvent;
          class var FSequence: Int32;
  
          constructor Create (AOwner: TComponent); override;
       end; // Class: TFrame1 //
  
    implementation
  
    {$R *.fmx}
  
    constructor TItem_Frame.Create (AOwner: TComponent);
    begin
       inherited Create (AOwner);
  
       Self.Name := Format ('Frame_%d', [FSequence]);
       FSequence := FSequence + 1;
    end; // Create //
  
    procedure TItem_Frame.SpeedButton1Click (Sender: TObject);
    begin
       if Assigned (FOnInsert)
          then FOnInsert (Sender);
    end;
  
    end.
  </code></pre>
  
  <p>The code above describes a TFrame with three components. By pressing the speed button an object is added to the listbox in the main program as follows:</p>
  
  <pre><code>  unit tlist_main;
  
    interface
  
    uses
       System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
       FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.Layouts,
       FMX.ListBox,
       tlist_item;
  
    type
       TMain_Form = class(TForm)
        ListBox: TListBox;
        procedure FormCreate(Sender: TObject);
  
       private
          procedure do_insert (Sender: TObject);
  
       public
  
       end; // Class: TForm1 //
  
    var
      Main_Form: TMain_Form;
  
    implementation
  
    {$R *.fmx}
  
    procedure TMain_Form.FormCreate (Sender: TObject);
    begin
       do_insert (ListBox);
    end; // FormCreate //
  
    procedure TMain_Form.do_insert (Sender: TObject);
    var
       frame: TItem_Frame;
    begin
       frame := TItem_Frame.Create (ListBox);
       frame.Parent := ListBox;
       frame.Position.Y := frame.FSequence * frame.Height;
       frame.Width := ListBox.Width;
       frame.FOnInsert := do_insert;
       ListBox.InsertObject (frame.FSequence - 1, frame);
    end; // do_insert //
  
    end.
  </code></pre>
  
  <p>The error occurs in do_insert at the InsertObject call and happen both at Win32 and Android. I wonder whether this is a bug or an error of mine. Could anyone help me out?</p>