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 03-03-2013
teecweb teecweb is offline
Miembro
NULL
 
Registrado: feb 2013
Posts: 64
Poder: 12
teecweb Va por buen camino
Agregar ID a checkboxlist en delphi

Holas
Este es el codigo para agregar CheckListBox dinamico pero a este codigo quiero agregar el Id por checkbox y asi depues hacer el recorrido de la lista de checkbox ..por favor me podrian indicar como ahcer la sintaxis para agregar el ID de cada checkbox....eh buscado en google y no eh encontrado gracias por su respuesta.
Código Delphi [-]

scale :=8;
for i := 0 to listado.Count - 1 do
           begin
            j :=5; 
            scale :=scale+ (j+15);
            CheckListBox := TNewCheckListBox.Create(Page);
            CheckListBox.Top := Buttona.Top + Buttona.Height + ScaleY(scale);
            CheckListBox.Width := 410;
            CheckListBox.Height :=40;
            CheckListBox.Flat := True;
            CheckListBox.Parent := Page.Surface;
            CheckListBox.OnClick:=@uninstaller;
            CheckListBox.AddCheckBox(listado[i], 'qwqw', 0, False, True, True, True, nil);
           end;
Responder Con Cita
  #2  
Antiguo 03-03-2013
Avatar de ecfisa
ecfisa ecfisa is offline
Moderador
 
Registrado: dic 2005
Ubicación: Tres Arroyos, Argentina
Posts: 10.508
Poder: 36
ecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to behold
Hola teecweb.

No entiendo a que te refieres con "ID".

Si es a la posición que ocupa el ítem actual, la podes obtener mediante la propiedad ItemIndex:
Código Delphi [-]
  Caption:= IntToStr(Integer(CheckListBox1.ItemIndex));

En cambio si "ID" se refiere al campo de un DataSet, un ejemplo para cargar un campo de texto y el campo "ID" :
Código Delphi [-]
procedure TForm1.btnCargarClick(Sender: TObject);
begin
  with DataSet do
  begin
    Open;
    while not Eof do
    begin
      CheckListBox1.AddItem(FieldByName('CAMPO1').AsString,
        TObject(FieldByName('ID').AsInteger));
      Next
    end;
    Close
  end
end;

Para obtener el valor: (en el ejemplo se muestra)
Código Delphi [-]
procedure TForm1.CheckListBox1Click(Sender: TObject);
begin
  with CheckListBox1 do
    ShowMessage('Item: '+Items[ItemIndex] + #10#13 +
      'ID: ' + IntToStr(Integer(Items.Objects[ItemIndex])));
end;

Saludos.
__________________
Daniel Didriksen

Guía de estilo - Uso de las etiquetas - La otra guía de estilo ....

Última edición por ecfisa fecha: 03-03-2013 a las 20:45:15.
Responder Con Cita
  #3  
Antiguo 04-03-2013
teecweb teecweb is offline
Miembro
NULL
 
Registrado: feb 2013
Posts: 64
Poder: 12
teecweb Va por buen camino
Click en cada uno de los checkbox devolver el text

Holas..gracias por surespuesta

con respecto a tu primer codigo..devuelve el indice de los checbox en un checkboxlist:
Código Delphi [-]
  Caption:= IntToStr(Integer(CheckListBox1.ItemIndex));

lo eh agregrado asi en la funcion de onclick por checbox:
Código Delphi [-]
procedure uninstaller(Sender: TObject);
var path String;
begin
if (Sender is TNewCheckListBox) then
begin
     path:= IntToStr(Integer(CheckListBox.ItemIndex));
      MsgBox(path,mbInformation, MB_OK);
end;

por ejemplo mi for para la creacion de checkbolist que se encuentra arriba ..devuelve asi
[checkbox] = es la casilla de checkbox

[checkbox]'aaaaa'
[checkbox]'aaaaa'
[checkbox]'aaaaa'
[checkbox]'aaaaa'
[checkbox]'aaaaa'

Entonces cada vez que hago click a mi funcion uninstaller me deberia devolver la posicion de los checkboxlist por MsgBox :
0
1
2
3
4
pero en cambio me devuelve asi segun el codigo que usted me envio:
Código Delphi [-]
  Caption:= IntToStr(Integer(CheckListBox1.ItemIndex));

-1
-1
-1
-1
0

En realidad llevo una
2semana en el lenguaje delphi ..por favor alguna solucion
Tambien quisiera saber cual es el codigo para retornar el text de los checkbox al hacer click en cada uno de ellos..gracias por su respuesta..estare al tanto
Responder Con Cita
  #4  
Antiguo 04-03-2013
Avatar de ecfisa
ecfisa ecfisa is offline
Moderador
 
Registrado: dic 2005
Ubicación: Tres Arroyos, Argentina
Posts: 10.508
Poder: 36
ecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to behold
Hola teecweb.

No cuál sea el contenido del TCheckListBox, pero basta con que realices esta simple prueba en una nueva aplicación para comprobar que la propiedad ItemIndex devuelve el valor del índice actual:
Código Delphi [-]
...
procedure TForm1.FormCreate(Sender: TObject);
var
  i: Integer;
begin
  for i:= 1 to 10 do
    CheckListBox1.Items.Add('Item '+IntToStr(i));
end;

procedure TForm1.CheckListBox1Click(Sender: TObject);
begin
  ShowMessage('Indice item actual: '+IntToStr(Integer(CheckListBox1.ItemIndex))+#10+
              'Valor item actual : '+CheckListBox1.Items[CheckListBox1.ItemIndex]);
end;
...
Es decir que si el CheckListBox tiene algún contenido, el código:
Código Delphi [-]
procedure TForm1.CheckListBox1Click(Sender: TObject);
begin
  Caption:= IntToStr(Integer(CheckListBox1.ItemIndex));
end;
mostrará el índice actualmente seleccionado.

Lo que podría suceder es que no estés llamándo el código en el evento OnClick del TCheckListBox, en ese caso sí es necesario comprobar el valor de la propiedad ItemIndex:
Código Delphi [-]
procedure TForm1.Button1Click(Sender: TObject);
begin
  if CheckListBox1.ItemIndex = -1 then
    ShowMessage('¿ No le parece que debería seleccionar algo primero ?')
  else
    Caption:= IntToStr(Integer(CheckListBox1.ItemIndex));
end;

Saludos.
__________________
Daniel Didriksen

Guía de estilo - Uso de las etiquetas - La otra guía de estilo ....
Responder Con Cita
  #5  
Antiguo 04-03-2013
teecweb teecweb is offline
Miembro
NULL
 
Registrado: feb 2013
Posts: 64
Poder: 12
teecweb Va por buen camino
ok, muchas gracias estare probando el codigo
Responder Con Cita
  #6  
Antiguo 04-03-2013
teecweb teecweb is offline
Miembro
NULL
 
Registrado: feb 2013
Posts: 64
Poder: 12
teecweb Va por buen camino
Talking

Asi creo mi control de checkbolist..el codigo es para un instalador inno setup y innosetup utiliza el pascal que es parecido al delphi bueno es lo que segun investigue
Código Delphi [-]
[code]
//CODIGO PARA ONCLICK

 var 
  Page: TWizardPage;
  Buttona TNewButton;
   CheckListBox1: TNewCheckListBox;

procedure uninstaller(Sender: TObject);
begin        
        MsgBox('Indice item actual: '+IntToStr(Integer(CheckListBox1.ItemIndex)),mbInformation, MB_OK);

end;

procedure CreateTheWizardPages;
  var 

  Edit: TNewEdit;
  PasswordEdit: TPasswordEdit;
  listado: TStrings;
  inicio: Integer;
  scale : Integer;
  scale1:Integer;
  j:Integer;
  n: integer;

begin
  { TButton and others }
  Page := CreateCustomPage(wpSelectDir, 'Custom wizard page controls', 'TButton and others');

  Buttona := TNewButton.Create(Page);
  Buttona.Width := ScaleX(75);
  Buttona.Height := ScaleY(23);
  Buttona.Caption := 'TNewButton';
  Buttona.Parent := Page.Surface;
  Buttona.Visible := true;
   Buttona.OnClick := @ButtonOnClick;

                scale :=8;
             for inicio:= 1 to 10 do
             begin
             CheckListBox1 := TNewCheckListBox.Create(Page);
               j :=5; 
                scale :=scale+ (j+15);
                CheckListBox1 := TNewCheckListBox.Create(Page);//TNewCheckListBox.Create(WizardForm.ScriptDlgPanel);
                CheckListBox1.Top := Buttona.Top + Buttona.Height + ScaleY(scale);
                CheckListBox1.Width := 410;
                CheckListBox1.Height :=40;
                CheckListBox1.Parent := Page.Surface;
                CheckListBox1.OnClick:=@uninstaller;
                CheckListBox1.AddCheckBox('Item'+IntToStr(inicio), 'qwqw', 0, False, True, True, True, nil);
             end;
end;

ya eh probado el codigo que usted me mando..y lo eh hecho asi como esta arriba..aun asi me bota el index -1..gracias por su pronta respuesta...En el codigo que me envio hay eventos asi 'TForm1.FormCreate' en inno setup no se genera estos eventos .
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
Recorrer checkboxlist en pascal para un realizar en INNOSETUP teecweb Varios 1 02-03-2013 07:23:48
Agregar mas colores de fuente a Delphi candylolz OOP 5 07-08-2012 16:37:55
Agregar una linea en uses en delphi 10 piruchin Varios 3 11-04-2011 12:57:24
Agregar componente Delphi 8 elaprendizprog Impresión 4 20-03-2009 18:11:23
Agregar sonido en Delphi jescar .NET 2 17-09-2006 08:30:04


La franja horaria es GMT +2. Ahora son las 16:50:37.


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