Delphi 为什么我的TListBox在最后一个TListBox项被选中时变为空白? 问题

Delphi 为什么我的TListBox在最后一个TListBox项被选中时变为空白? 问题,delphi,listbox,firemonkey,tlistbox,Delphi,Listbox,Firemonkey,Tlistbox,当最后一个TListBoxItem被编程选中时,MyTListBoxItem将变为空白。为了更好地说明这一点,以下是我所说的“空白”的意思: 上下文 我正在从TJSONArray生成一个列表。每个项目看起来像{“event\u code”,“event\u name”} 然后,我比较事件代码是否写在第二个TJSONArray:json\u响应\u可用的事件上。如果是,则将选中ListBoxItem 代码 并且lb_item.isChecked:=false工作正常,但是当设置lb_item

当最后一个
TListBoxItem
被编程选中时,My
TListBoxItem
将变为空白。为了更好地说明这一点,以下是我所说的“空白”的意思:


上下文 我正在从
TJSONArray
生成一个列表。每个项目看起来像
{“event\u code”,“event\u name”}

然后,我比较事件代码是否写在第二个
TJSONArray
json\u响应\u可用的事件上。如果是,则将选中
ListBoxItem


代码 并且
lb_item.isChecked:=false
工作正常,但是当设置
lb_item.isChecked:=true
时,它会奇怪地变为空白

为什么会这样?如果有更好的方法来做我正在做的事情,我们将非常感谢你的帮助

procedure TFormHome.TimerGetEventsTimer(Sender: TObject);
var

    K                  : Integer;
    Z                  : Integer;
    ListCount          : Integer;
    AvailableList_Count: Integer;

    lb_item: TListBoxItem;

    event_code_first_array: string;
    event_code  : string;
    event_name  : string;

begin

    // Disable this timer for now
    TimerGetEvents.Enabled := false;

    // Get List of Notifications
    json_response_events           := DM_Auth0.ServerMethods1Client.GetEventsCodeAndDescription(communication_token);
    json_response_available_events := DM_Auth0.ServerMethods1Client.GetAllowedNotificationsList(communication_token, genset_id);

    ListCount                      := json_response_events.Count -1;
    AvailableList_Count            := json_response_available_events.Count - 1;

        for K := 0 to (ListCount) do
        begin

            // Get complete Event Code and Name
            event_name := json_response_events.Items[K].toString;

            // Get Event Code
            event_code_first_array := StringReplace(event_name.Split([':'])[0], '"', '', [rfReplaceAll]);

            // Get Event Name
            event_name   := StringReplace(event_name.Split([':'])[1], '"', '', [rfReplaceAll]);

            // Create ListBoxItem
            lb_item                := TListBoxItem.Create(self);
            lb_item.Parent         := lb_notifications;
            lb_item.Text           := event_name;
            lb_item.StyleLookup    := 'listboxitemleftdetail';

            // Check if this Item code is available
            for Z := 0 to (AvailableList_Count) do
            begin

                if json_response_available_events.Items[Z] <> nil then
                begin

                    // Get Event Code
                    event_code := json_response_available_events.Items[Z].toString;
                    // Format
                    event_code := StringReplace(event_code, '"', '', [rfReplaceAll]);

                    if event_code_first_array.Contains(event_code) then
                    begin

                        if K <= ListCount then
                        begin
                            lb_item.IsChecked  := true;
                            lb_item.IsSelected := false;
                        end;

                    end;

                end;

            end;

        end;

end;
if K < ListCount then
 begin
 lb_item.IsChecked  := true;
 lb_item.IsSelected := false;
end;
if K = ListCount then
 begin
 lb_item.Text := 'Deadpool for President';
end;