Al parecer el componente TListBox si tiene un problema
En este código estoy usando un TCombobox, TListBox y un TStrings.
Las funciones que alimentan y leen de las listas son las mismas, el objeto de lista es pasado como parámetro y la lista del TListBox genera error.
Código Delphi
[-]
procedure TForm1.LlenarListasClick(Sender: TObject);
procedure LlenarListaDatos(SL: TStrings);
begin
SL.BeginUpdate;
try
SL.Clear;
try
FDMemTable1.First;
while not FDMemTable1.Eof do
begin
SL.AddObject(FDMemTable1Valor.AsString, TObject(FDMemTable1Codigo.AsInteger));
FDMemTable1.Next;
end;
finally
FDMemTable1.First;
end;
finally
SL.EndUpdate;
end;
end;
begin
LlenarListaDatos(FLista);
LlenarListaDatos(ComboBox1.Items);
LlenarListaDatos(ListBox1.Items);
Memo1.Lines.Assign(FLista); end;
procedure TForm1.ObtDeListasClick(Sender: TObject);
procedure EstValores(EditS, EditO: TEdit; SL: TStrings);
var
lIndex: Integer;
begin
EditS.Clear;
EditO.Clear;
if (SL.Count = 0) then
Exit;
try
lIndex := SL.IndexOf(FDMemTable1Valor.AsString);
if lIndex >= 0 then
EditS.Text := SL[lIndex];
except
on E: Exception do
EditS.Text := 'Error: ' + E.Message;
end;
try
lIndex := SL.IndexOfObject(TObject(FDMemTable1Codigo.AsInteger));
if lIndex >= 0 then
EditO.Text := IntToStr(Integer(SL.Objects[lIndex]));
except
on E: Exception do
EditO.Text := 'Error: ' + E.Message;
end;
end;
begin
EstValores(EditCBS, EditCBO, ComboBox1.Items);
EstValores(EditLBS, EditLBO, ListBox1.Items);
EstValores(EditSLS, EditSLO, FLista);
end;