Club Delphi  
    FTP   CCD     Buscar   Trucos   Trabajo   Foros

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

Grupo de Teaming del ClubDelphi

Respuesta
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 19-10-2022
steelha steelha is offline
Miembro
 
Registrado: mar 2012
Posts: 158
Poder: 13
steelha Va por buen camino
Muchas gracias, he podido resolver el problema aca dejo código completo. Si lo ven feíto y quieren aportar algo para que se vea mejor estéticamente y mejorar rendimiento sean bienvenidos XD. Ahora me toca la parte dolorosa guardar la información de cada uno en su respectivos lugar y luego cargarla para consultar T_T (siento que me va a doler la cabeza pero tengo a mano aspirina XD).

Código Delphi [-]
procedure TfrmPacientes.Crear_panel();
Var
 LPanel   : TCategoryPanel;
 Cat      : TCategoryButtons;
 npaneles : Integer;
 but      : TButtonItem;
 i, j     : Integer;
 edt      : TEdit;
 mem      : TMemo;
 chk      : TCheckBox;
 lbl      : TLabel;
 contcomp : Integer;
 tp       : Integer;
 sumaalt  : Integer;
Const
  cl = 165;  //Los controles estaran siempre en la left 165
  ll = 5;    //Los label estaran siempre en la pos left 5
  sp = 5;    //Separacion etre controles

  lw = 154;
  ew = 160;  eh = 21;
  mw = 510;  mh = 90;
  cw = 25;   ch = 17;
begin
  DM.QryPGrupos.Close;
  DM.QryPGrupos.Parameters.ParamByName('p').Value := DM.QryPlantillaDefaultidPlantilla.Value;
  DM.QryPGrupos.Open;
  npaneles := DM.QryPGrupos.RecordCount;

  contcomp := frmPacientes.ComponentCount;

  for i := 1 to npaneles do
  begin
      LPanel:=TCategoryPanel.Create(micategorygroup);
      LPanel.Caption:= Trim(DM.QryPGrupos.FieldByName('DatosCaptionGrupo').AsString);
      LPanel.PanelGroup:= micategorygroup;
      LPanel.TabOrder  := i;
      LPanel.Name := Trim('Grupo' + i.ToString);

      Cat := TCategoryButtons.Create(lPanel);
      Cat.Name := 'Category' + i.ToString;
      cat.Parent := LPanel;
      Cat.Align := alClient;
      cat.ButtonWidth := 675;

      DM.QryPButtons.Close;
      DM.QryPButtons.Parameters.ParamByName('p').Value   := DM.QryPlantillaDefaultidPlantilla.Value;
      DM.QryPButtons.Parameters.ParamByName('cap').Value := DM.QryPGrupos.FieldByName('DatosCaptionGrupo').AsString;;
      DM.QryPButtons.Open;

      LPanel.Height := (50 * (DM.QryPButtons.RecordCount));
      tp := 2; //Posicion inicial del primer control

      //Para calcular la altura del proximo control se utilizara
      //tp = tp + alturadelcontrol + sp;
      //Donde tp es el top actual y sp es la separacion entre controles

      // Para cada Grupo, crear los botones...
      for j := 0 to (DM.QryPButtons.RecordCount -1) do
      begin
          contcomp := contcomp + 1;
          //Crear el label con la nota del campo a introducir dato
          lbl       := TLabel.Create(Self);
          lbl.Name  := 'lbl'+IntToStr(contcomp);
          lbl.Parent:= Cat;
          lbl.Caption:= Trim(DM.QryPButtonsDatosDetalle.Value);
          lbl.Top   := tp;
          lbl.Left  := ll;

        // Crear el control segun su tipo y ubicarlo al lado del label
        if (Trim(DM.QryPButtonsDatosTipo.Value) = 'TEdit') Or (Trim(DM.QryPButtonsDatosTipo.Value) = 'Edit') then
        begin
          edt       := TEdit.Create(Self);
          edt.Name  := 'Edt'+IntToStr(contcomp);
          edt.Parent:= Cat;
          edt.Tag   := DM.QryPButtonsidDatos.Value;
          edt.Width := ew;
          edt.Text  := '';
          edt.Top   := tp;
          edt.Left  := cl;

          tp := tp + eh + sp;
        end;

        if (Trim(DM.QryPButtonsDatosTipo.Value) = 'TMemo') Or (Trim(DM.QryPButtonsDatosTipo.Value) = 'Memo') then
        begin
          mem       := TMemo.Create(Self);
          mem.Name  := 'Mem'+IntToStr(contcomp);
          mem.Parent:= Cat;
          mem.Tag   := DM.QryPButtonsidDatos.Value;
          mem.Width := mw;
          mem.Text  := '';
          mem.Top   := tp;
          mem.Left  := cl;

          tp := tp + mh + sp;
        end;

        if (Trim(DM.QryPButtonsDatosTipo.Value) = 'TCheckbox') Or (Trim(DM.QryPButtonsDatosTipo.Value) = 'Checkbox') then
        begin
          chk       := TCheckBox.Create(Self);
          chk.Name  := 'Chk'+IntToStr(contcomp);
          chk.Parent:= Cat;
          chk.Tag   := DM.QryPButtonsidDatos.Value;
          chk.Width := cw;
          chk.Caption:='';
          chk.Top   := tp;
          chk.Left  := cl;

          tp := tp + ch + sp;
        end;

        //but := TButtonItem.Create(Cat.Categories.Add.Items);
        //but.Caption := DM.QryPButtons.FieldByName('DatosDetalle').AsString;

        DM.QryPButtons.Next;
      end;
      //Reajustar altura del panel
      LPanel.Height := tp + 25;

      DM.QryPGrupos.Next;
  end;
end;
Responder Con Cita
  #2  
Antiguo 19-10-2022
Avatar de Neftali [Germán.Estévez]
Neftali [Germán.Estévez] Neftali [Germán.Estévez] is offline
[becario]
 
Registrado: jul 2004
Ubicación: Barcelona - España
Posts: 18.293
Poder: 10
Neftali [Germán.Estévez] Es un diamante en brutoNeftali [Germán.Estévez] Es un diamante en brutoNeftali [Germán.Estévez] Es un diamante en bruto
Yo creo que se podría "arreglar" la parte de los IF que crea los componentes. Es muy repetitivo y usando RTTI y la herencia de clases podría quedarse más sencillo.
Y si el número de controles diferentes crece, te saldrá más a cuente para no tener qui ir copiando y pegando ese trozo:

Así esto:

Código Delphi [-]
// Para cada Grupo, crear los botones...       for j := 0 to (DM.QryPButtons.RecordCount -1) do       begin           contcomp := contcomp + 1;           //Crear el label con la nota del campo a introducir dato           lbl       := TLabel.Create(Self);           lbl.Name  := 'lbl'+IntToStr(contcomp);           lbl.Parent:= Cat;           lbl.Caption:= Trim(DM.QryPButtonsDatosDetalle.Value);           lbl.Top   := tp;           lbl.Left  := ll;          // Crear el control segun su tipo y ubicarlo al lado del label         if (Trim(DM.QryPButtonsDatosTipo.Value) = 'TEdit') Or (Trim(DM.QryPButtonsDatosTipo.Value) = 'Edit') then         begin           edt       := TEdit.Create(Self);           edt.Name  := 'Edt'+IntToStr(contcomp);           edt.Parent:= Cat;           edt.Tag   := DM.QryPButtonsidDatos.Value;           edt.Width := ew;           edt.Text  := '';           edt.Top   := tp;           edt.Left  := cl;            tp := tp + eh + sp;         end;          if (Trim(DM.QryPButtonsDatosTipo.Value) = 'TMemo') Or (Trim(DM.QryPButtonsDatosTipo.Value) = 'Memo') then         begin           mem       := TMemo.Create(Self);           mem.Name  := 'Mem'+IntToStr(contcomp);           mem.Parent:= Cat;           mem.Tag   := DM.QryPButtonsidDatos.Value;           mem.Width := mw;           mem.Text  := '';           mem.Top   := tp;           mem.Left  := cl;            tp := tp + mh + sp;         end;          if (Trim(DM.QryPButtonsDatosTipo.Value) = 'TCheckbox') Or (Trim(DM.QryPButtonsDatosTipo.Value) = 'Checkbox') then         begin           chk       := TCheckBox.Create(Self);           chk.Name  := 'Chk'+IntToStr(contcomp);           chk.Parent:= Cat;           chk.Tag   := DM.QryPButtonsidDatos.Value;           chk.Width := cw;           chk.Caption:='';           chk.Top   := tp;           chk.Left  := cl;            tp := tp + ch + sp;         end;

Se podría quedar en algo como esto:

// Para cada Grupo, crear los botones...
for j := 0 to (DM.QryPButtons.RecordCount -1) do
begin
contcomp := contcomp + 1;
//Crear el label con la nota del campo a introducir dato
CreateComponent(TLabel,DM.QryPButtonsidDatos.Value, 5, ll, DM.QryPButtons.FieldByName('CaptionLabel').AsString);

var sDatosTipo:string := Trim(DM.QryPButtons.FieldByName('DatosTipo').AsString);

// Crear el control segun su tipo y ubicarlo al lado del label
if (sDatosTipo = 'TEdit') Or (sDatosTipo = 'Edit') then begin
// Crear un Edit
CreateComponent(TEdit,DM.QryPButtonsidDatos.Value, ew, cl, '');
tp := tp + eh + sp;
end;

if (sDatosTipo = 'TMemo') Or (sDatosTipo = 'Memo') then begin
// Crear un memo
CreateComponent(Tmemo,DM.QryPButtonsidDatos.Value, mw, cl, '');
tp := tp + mh + sp;
end;

if (sDatosTipo = 'TCheckbox') Or (sDatosTipo = 'Checkbox') then begin
// crear un checkbox
CreateComponent(TCheckbox, DM.QryPButtonsidDatos.Value, cw, cl, '');
tp := tp + ch + sp;
end;

//but := TButtonItem.Create(Cat.Categories.Add.Items);
//but.Caption := QryButtons.FieldByName('DatosDetalle').AsString;

QryButtons.Next;
end;

Y con el procedimiento definido así:

Código Delphi [-]
  procedure CreateComponent(CompClass:TComponentClass; iTag:integer; iWidth, iLeft:integer; sCaption:string);
  begin
    comp       := TWinControl(CompClass.Create(Self));       // Crear el componente (usando TWinControl) a partir de la clase
    comp.Name  := comp.ClassName + IntToStr(contcomp);
    comp.Parent:= Cat;
    comp.Tag   := iTag;
    comp.Width := iWidth;
    // comp.Text  := '';
    comp.Top   := tp;
    comp.Left  := iLeft;
    if IsPublishedProp(comp, 'Text') then                   // RTTI para propiedades published
      SetPropValue(comp, 'Text', String.Empty);
    if IsPublishedProp(comp, 'Caption') then
      SetPropValue(comp, 'Caption', sCaption);
  end;

Y hay que añadir System.TypInfo al USES.
la idea con esto es utilizar RTTI para poder crear ls diferentes componentes (diferentes clases) en un mismo punto. Herencia para las diferentes clases (TComponentClass) y RTTI para preguntar y asigar las propiedades published de los componentes.
__________________
Germán Estévez => Web/Blog
Guía de estilo, Guía alternativa
Utiliza TAG's en tus mensajes.
Contactar con el Clubdelphi

P.D: Más tiempo dedicado a la pregunta=Mejores respuestas.
Responder Con Cita
  #3  
Antiguo 19-10-2022
Avatar de Neftali [Germán.Estévez]
Neftali [Germán.Estévez] Neftali [Germán.Estévez] is offline
[becario]
 
Registrado: jul 2004
Ubicación: Barcelona - España
Posts: 18.293
Poder: 10
Neftali [Germán.Estévez] Es un diamante en brutoNeftali [Germán.Estévez] Es un diamante en brutoNeftali [Germán.Estévez] Es un diamante en bruto
Yo creo que se podría "arreglar" la parte de los IF que crea los componentes. Es muy repetitivo y usando RTTI y la herencia de clases podría quedarse más sencillo.
Y si el número de controles diferentes crece, te saldrá más a cuente para no tener qui ir copiando y pegando ese trozo:

Así esto:

Código Delphi [-]
// Para cada Grupo, crear los botones...
      for j := 0 to (DM.QryPButtons.RecordCount -1) do
      begin
          contcomp := contcomp + 1;
          //Crear el label con la nota del campo a introducir dato
          lbl       := TLabel.Create(Self);
          lbl.Name  := 'lbl'+IntToStr(contcomp);
          lbl.Parent:= Cat;
          lbl.Caption:= Trim(DM.QryPButtonsDatosDetalle.Value);
          lbl.Top   := tp;
          lbl.Left  := ll;

        // Crear el control segun su tipo y ubicarlo al lado del label
        if (Trim(DM.QryPButtonsDatosTipo.Value) = 'TEdit') Or (Trim(DM.QryPButtonsDatosTipo.Value) = 'Edit') then
        begin
          edt       := TEdit.Create(Self);
          edt.Name  := 'Edt'+IntToStr(contcomp);
          edt.Parent:= Cat;
          edt.Tag   := DM.QryPButtonsidDatos.Value;
          edt.Width := ew;
          edt.Text  := '';
          edt.Top   := tp;
          edt.Left  := cl;

          tp := tp + eh + sp;
        end;

        if (Trim(DM.QryPButtonsDatosTipo.Value) = 'TMemo') Or (Trim(DM.QryPButtonsDatosTipo.Value) = 'Memo') then
        begin
          mem       := TMemo.Create(Self);
          mem.Name  := 'Mem'+IntToStr(contcomp);
          mem.Parent:= Cat;
          mem.Tag   := DM.QryPButtonsidDatos.Value;
          mem.Width := mw;
          mem.Text  := '';
          mem.Top   := tp;
          mem.Left  := cl;

          tp := tp + mh + sp;
        end;

        if (Trim(DM.QryPButtonsDatosTipo.Value) = 'TCheckbox') Or (Trim(DM.QryPButtonsDatosTipo.Value) = 'Checkbox') then
        begin
          chk       := TCheckBox.Create(Self);
          chk.Name  := 'Chk'+IntToStr(contcomp);
          chk.Parent:= Cat;
          chk.Tag   := DM.QryPButtonsidDatos.Value;
          chk.Width := cw;
          chk.Caption:='';
          chk.Top   := tp;
          chk.Left  := cl;

          tp := tp + ch + sp;
        end;

Se podría quedar en algo como esto:

Código Delphi [-]
// Para cada Grupo, crear los botones...
      for j := 0 to (DM.QryPButtons.RecordCount -1) do
      begin
          contcomp := contcomp + 1;
          //Crear el label con la nota del campo a introducir dato
          CreateComponent(TLabel,DM.QryPButtonsidDatos.Value, 5, ll, DM.QryPButtons.FieldByName('CaptionLabel').AsString);

        var sDatosTipo:string := Trim(DM.QryPButtons.FieldByName('DatosTipo').AsString);

        // Crear el control segun su tipo y ubicarlo al lado del label
        if (sDatosTipo = 'TEdit') Or (sDatosTipo = 'Edit') then begin
          // Crear un Edit
          CreateComponent(TEdit,DM.QryPButtonsidDatos.Value, ew, cl, '');
          tp := tp + eh + sp;
        end;

        if (sDatosTipo = 'TMemo') Or (sDatosTipo = 'Memo') then begin
          // Crear un memo
          CreateComponent(Tmemo,DM.QryPButtonsidDatos.Value, mw, cl, '');
          tp := tp + mh + sp;
        end;

        if (sDatosTipo = 'TCheckbox') Or (sDatosTipo = 'Checkbox') then begin
          // crear un checkbox
          CreateComponent(TCheckbox, DM.QryPButtonsidDatos.Value, cw, cl, '');
          tp := tp + ch + sp;
        end;

        //but := TButtonItem.Create(Cat.Categories.Add.Items);
        //but.Caption := QryButtons.FieldByName('DatosDetalle').AsString;

        QryButtons.Next;
      end;

Y con el procedimiento definido así:

Código Delphi [-]
  
procedure CreateComponent(CompClass:TComponentClass; iTag:integer; iWidth, iLeft:integer; sCaption:string);
  begin
    // Crear el componente (usando TWinControl) a partir de la clase
    comp       := TWinControl(CompClass.Create(Self));       
    comp.Name  := comp.ClassName + IntToStr(contcomp);
    comp.Parent:= Cat;
    comp.Tag   := iTag;
    comp.Width := iWidth;
    // comp.Text  := '';
    comp.Top   := tp;
    comp.Left  := iLeft;
    // RTTI para propiedades published
    if IsPublishedProp(comp, 'Text') then                  
      SetPropValue(comp, 'Text', String.Empty);
    if IsPublishedProp(comp, 'Caption') then
      SetPropValue(comp, 'Caption', sCaption);
  end;

Y hay que añadir System.TypInfo al USES.
la idea con esto es utilizar RTTI para poder crear los diferentes componentes (diferentes clases) en un mismo punto. Herencia para las diferentes clases (TComponentClass) y RTTI para preguntar y asigar las propiedades published de los componentes.
__________________
Germán Estévez => Web/Blog
Guía de estilo, Guía alternativa
Utiliza TAG's en tus mensajes.
Contactar con el Clubdelphi

P.D: Más tiempo dedicado a la pregunta=Mejores respuestas.
Responder Con Cita
  #4  
Antiguo 19-10-2022
steelha steelha is offline
Miembro
 
Registrado: mar 2012
Posts: 158
Poder: 13
steelha Va por buen camino
Ok probare. Gracias
Responder Con Cita
  #5  
Antiguo 20-10-2022
steelha steelha is offline
Miembro
 
Registrado: mar 2012
Posts: 158
Poder: 13
steelha Va por buen camino
Buenas, he copiado el codigo tal cual me indicas y agregado al use System.TypInfo. Pero primero tube que arreglar la linea donde dice
Código Delphi [-]
var sDatosTipo:string := Trim(DM.QryPButtons.FieldByName('DatosTipo').AsString);
me da error lo coloque como siempre hago
Código Delphi [-]
Procedure xxx
Var 
   StadosTipo : String;
begin
....
end;

Pero aun así consigo un error el el procedimiento de crear componente
[dcc32 Error] ufrmpacientes.pas(276): E2029 '(' expected but ':=' found

Código Delphi [-]
procedure TfrmPacientes.CreateComponent(CompClass: TComponentClass; iTag, iWidth, iLeft: integer; sCaption: string);
begin
    comp  := TWinControl(CompClass.Create(Self));
    comp.Name  := comp.ClassName + IntToStr(contcomp);
    comp.Parent:= Cat;
    comp.Tag   := iTag;
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
Ayuda componente cmm07 Varios 6 01-12-2008 16:42:20
Ayuda con un componente. Lucciano Conexión con bases de datos 2 12-04-2006 17:57:04
Ayuda con componente CelestronFan Varios 6 09-10-2005 17:39:40
Ayuda con componente raco Internet 2 17-02-2005 01:59:50
Ayuda con componente animal Varios 2 16-02-2005 07:49:47


La franja horaria es GMT +2. Ahora son las 23:26:53.


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