Código Delphi
[-]procedure TForm1.Button1Click(Sender: TObject);
begin
if ListBox1.Items.Capacity = 0 then
ShowMessage('Vacio')
else
Showmessage('Tiene asignados:'+IntToStr(ListBox1.Items.Capacity));
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
if ListBox1.Items.Count = 0 then
ShowMessage('Vacio')
else
Showmessage('Tiene asignados:'+IntToStr(ListBox1.Items.Count));
end;
En estos dos ejemplos, sería lo mismo utilizar
Capacity que
Count.
Aunque también conviene este apunte de la ayuda de Delphi, porque en algunos casos debe de utilizarse con otros propósitos:
Cita:
Indicates the number of strings the string list has allocated memory to hold.
property Capacity: Integer;
Description
Use Capacity to find out how much memory is available for holding strings, or to reallocate the memory to allow more or fewer strings.
Capacity is the number of entries in the string list that have been allocated, as opposed to Count, which is the number of strings in the list. Thus, Capacity is always greater than or equal to Count.
Adding new strings will cause the Capacity property to increase if necessary, but setting the Capacity property will not change the Count property. Do not set Capacity to a value less than Count, or the list will be truncated and Count will indicate that the list contains more strings than is the case. Also, if Capacity is set to a value less than Count, the memory used to store the strings that are dropped from the list (as opposed to the entries in the list that point to those strings) is not freed.
|
Un Saludo.