![]() |
![]() |
| Paypal | FTP | CCD | Buscar | Trucos | Trabajo | Foros |
|
|||||||
| Registrarse | FAQ | Miembros | Calendario | Guía de estilo | Buscar | Temas de Hoy | Marcar Foros Como Leídos |
![]() |
|
|
Herramientas | Buscar en Tema | Desplegado |
|
|
|
#1
|
|||
|
|||
|
Hola, sigo con esto es que hago lo siguiente
var inicio : TDateTime; Procedure TForm1.Create(Sender : TOject); var item : TListItem; begin inicio := now; item := ListView1.Add; item.Caption := 'PC01'; item.SubItems.Add('Libre'); end; Procedure TForm1.Timer1Timer(Sender : TOject); var item : TListItem; begin item.SubItems.Add(FormatDataTime('HH:mm:ss', Now - inicio); end; y me sale un error en tiempo de ejecución. Pero si agrego ListView1.Add en el evento OnTimer me da el tiempo en cada segundo |
|
#2
|
||||
|
||||
|
Código:
Procedure TForm1.Timer1Timer(Sender : TOject);
var
item : TListItem;
begin
item.SubItems.Add(FormatDataTime('HH:mm:ss', Now - inicio);
end;
La solución, acceder desde el timer al ListView: Código:
Procedure TForm1.Timer1Timer(Sender : TOject);
begin
ListView.items[3].SubItems[0] := (FormatDataTime('hh:nn:ss', Now - inicio);
end;
Por cierto, la cadena para formatear la hora, aunque es la más intuitiva, no es la correcta, para mostrar los minutos tienes que poner "nn". Saludos |
|
#3
|
||||
|
||||
|
Cita:
![]() |
|
#4
|
|||
|
|||
|
Gracias por tu respuesta, pero te cuento que sigo teniendo el mismo error que sale que no puedo acceder a una dirección de memoria.
|
|
#5
|
||||
|
||||
|
Código:
var i, subi:Integer;
begin
i:= 3;
subi:=0;
if i < ListView1.Items.Count then
begin
if subi < ListView1.Items[i].SubItems.Count then
begin
ListView1.Items[i].SubItems[subi] := 'Ocupado'
end
else
ShowMessage('no tiene subItems'); // crear el SubItem aqui ???
end
else
ShowMessage ('Elemento no existe'); // crear el Elemento aqui ???
![]() Por otra parte, en Listview1.columns debe haber definido al menos 2 columnas, ( la 0 y 1) Saludos |
|
#6
|
|||
|
|||
|
Muchas gracias por tu respuesta
. Te cuento que cuando me aparece la hora y hago click en otra parte del ListView, la hora se corta y aparece en donde hice click para seguir con el conteo. Otra cosa, como hago para que solo un subitem tome color ya que todos los subitems lo hacen. Te mando algo de código para que me puedas entender.procedure TForm1.ListView1ColumnClick(Sender: TObject; Column: TListColumn); begin nSortCol := Column.Index; ListView1.AlphaSort; end; procedure TForm1.Timer1Timer(Sender: TObject); var i : integer; begin if ListView1.Selected <> nil then ListView1.Selected.SubItems[1] := FormatDateTime('hh:nn:ss', Now - inicio); end; procedure TForm1.Abrir1Click(Sender: TObject); begin inicio:=Now; Timer1.Enabled := true; end; procedure TForm1.ListView1CustomDrawSubItem(Sender: TCustomListView; Item: TListItem; SubItem: Integer; State: TCustomDrawState; var DefaultDraw: Boolean); var i : integer; begin for i := 0 to ListView1.Items.Count - 1 do begin if ListView1.Items.Item[i].SubItems[0] = 'Libre' then ListView1.Canvas.Font.Color := RGB(0,120,0); end; end; Muchas gracias. Saludos ![]() |
|
#7
|
||||
|
||||
|
Holas de nuevo
![]() Cita:
Hay varias formas de hacerlo: - Usando el objeto TObjectList. (vease ayuda de delphi )- Usando una tabla en la que cada elemento es un registro con información asociada a cada PC. Yo me quedaria con la primera opción. En cuanto a lo del timer: Código:
procedure TForm1.Timer1Timer(Sender: TObject);
var
i : integer;
begin
for i:=0 to pred(listview1.items.count) do
if listview1.items[i].subItems[0] <>'Libre' then
ListView1.items[i].SubItems[1] := FormatDateTime('hh:nn:ss', Now - DatosPc[i].HoraInicio);
end;
Saludos |
![]() |
| Herramientas | Buscar en Tema |
| Desplegado | |
|
|
|