Club Delphi  
    FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Principal > Varios
Registrarse FAQ Miembros Calendario Guía de estilo Temas de Hoy

Grupo de Teaming del ClubDelphi

Respuesta
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 06-09-2006
gsilvei gsilvei is offline
Miembro
 
Registrado: jul 2006
Posts: 44
Poder: 0
gsilvei Va por buen camino
listbox

Hola a todos, tengo la siguiente procedure:
Código Delphi [-]
{$WRITEABLECONST ON}
procedure TForm1.SpeedButton2Click(Sender: TObject);
const
  i: integer = 0;
begin
     with ListBox4 do
        begin
         if i < Count then
          if Items[i+1] = 'S' then
           begin
             Self.Height := 739;
             Self.Width := 1024;
             Self.Left := 0;
             Self.Top := 0;
           end;
          if Items[i+1] = 'N' then
           begin
             Self.Height := 300;
             Self.Width := 550;
             Self.Left := 400;
             Self.Top := 400;
           end;
         if i < Count-1 then
            inc(i)
         else
            i:= 0;
        end;
    end;
end;
{$WRITEABLECONST OFF}

que recorre un listbox cada vez que hago clique en el speedbutton, la duda es que cuando cierro el form y ejecuto nuevamente, el no comienze a recorrer el listbox desde el comienzo y si desde el item que yo selecciono.
garcias por la ayuda.
saludos
Responder Con Cita
  #2  
Antiguo 06-09-2006
Avatar de seoane
[seoane] seoane is offline
Miembro Premium
 
Registrado: feb 2004
Ubicación: A Coruña, España
Posts: 3.717
Poder: 24
seoane Va por buen camino
Vamos a ver si encontramos la solución, para empezar el código que pones daría error al llegar al ultimo elemento, una versión corregida seria:

Código Delphi [-]
{$WRITEABLECONST ON}
procedure TForm1.SpeedButton2Click(Sender: TObject);
const
  i: integer = 0;
begin
   with ListBox4 do
      begin
       if i < Count then
        if Items[i] = 'S' then // Aqui estaba el error al poner i+1
         begin
           Self.Height := 739;
           Self.Width := 1024;
           Self.Left := 0;
           Self.Top := 0;
         end;
        if Items[i] = 'N' then
         begin
           Self.Height := 300;
           Self.Width := 550;
           Self.Left := 400;
           Self.Top := 400;
         end;
       i:= (i + 1) mod Count;
      end;
end;
{$WRITEABLECONST OFF}

El codigo anterior recorre el listbox pero sin mover el elemento seleccionado, si lo que queremos es mover el elemento seleccionado el codigo todavia es mas simple:

Código Delphi [-]
procedure TForm1.SpeedButton2Click(Sender: TObject);
begin
   with ListBox4 do
      begin
       ItemIndex:= (ItemIndex + 1) mod Count;
       if ItemIndex < Count then
        if Items[ItemIndex] = 'S' then
         begin
           Self.Height := 739;
           Self.Width := 1024;
           Self.Left := 0;
           Self.Top := 0;
         end;
        if Items[ItemIndex] = 'N' then
         begin
           Self.Height := 300;
           Self.Width := 550;
           Self.Left := 400;
           Self.Top := 400;
         end;
      end;
end;

Con el codigo anterior solo tenemos que seleccionar el elemento de partida y con cada clic boton se seleccionara el siguiente. Ahora bien, si quieres indicar en que elemento debe comenzar, eso lo puedes hacer manualmente, o en el evento OnCreate del formulario, colocar la propiedad ItemIdex del Listbox en el elemento adecuado. Pero si lo que quieres es que nuestro programa recuerde en que posicion se quedo en la ejecucion anterior no te queda mas remedio que guardarlo, bien sea en un archivo o en el registro:

Por ejemplo en un archivo:
Código Delphi [-]
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  with TStringList.Create do
  try
    Values['POS']:= IntToStr(ListBox4.ItemIndex);
    SaveToFile(ChangeFileExt(ParamStr(0),'.ini'));
  finally
    Free;
  end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  if FileExists(ChangeFileExt(ParamStr(0),'.ini')) then
    with TStringList.Create do
    try
      LoadFromFile(ChangeFileExt(ParamStr(0),'.ini'));
      ListBox4.ItemIndex:= StrToIntDef(Values['POS'],-1);
    finally
      Free;
    end;
end;
Responder Con Cita
  #3  
Antiguo 06-09-2006
gsilvei gsilvei is offline
Miembro
 
Registrado: jul 2006
Posts: 44
Poder: 0
gsilvei Va por buen camino
La procedure que Seoane coloco, funciona correctamente, diria que mejoro el procedimiento que necesitaba hacer.
muchas gracias,
saludos
Responder Con Cita
Respuesta



Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro

Temas Similares
Tema Autor Foro Respuestas Último mensaje
ListBox Tala OOP 3 21-06-2006 16:31:46
uso del listbox majosf Conexión con bases de datos 3 25-07-2005 10:59:25
2 Listbox y BD .... elbilla Varios 5 04-11-2004 11:06:12
ListBox neon OOP 2 09-08-2004 11:15:27
listbox cesarjbf OOP 1 16-10-2003 13:17:21


La franja horaria es GMT +2. Ahora son las 16:42:59.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi
Copyright 1996-2007 Club Delphi