Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Varios (https://www.clubdelphi.com/foros/forumdisplay.php?f=11)
-   -   Problemas con un statusbar (https://www.clubdelphi.com/foros/showthread.php?t=65116)

José Luis Garcí 21-11-2009 12:13:48

Problemas con un statusbar
 
Hola compañeros el problema es el siguiente creo por código un statusbar y creo el parent a un dbgrid, lo posiciono y entonces creo los paneles, hasta aquí todo bien de momento, eñll problema aparece cuando hago lo siguiente
Código Delphi [-]
Footer.Panels.Count

Me da un Error

---------------------------
Project1
---------------------------
Access violation at address 004E3D5C in module 'Project1.exe'. Read of address 00000260.
---------------------------
Aceptar
---------------------------

Tenéis idea por que

jhonny 21-11-2009 15:42:16

Para este caso, creo que sería muy conveniente que nos muestres la parte de tu código, donde creas dicho statusbar en tiempo de ejecución.

José Luis Garcí 21-11-2009 17:34:32

Gracias por tu ayuda Jhonny, respondiendo a la pregunta a qui va las partes del código

Variables generales
Código Delphi [-]
var
  Form1: TForm1;
  footer:tstatusbar;
  fin, Colfin,colini: integer;

El OnCreate del Form
Código Delphi [-]
procedure TForm1.FormCreate(Sender: TObject);
var footer:tstatusbar;
  i:integer;
begin
     footer:=TStatusBar.Create(self);
   //  footer.SetParentComponent(DBGrid1);
     footer.Parent:=DBGrid1;
     footer.Top:=DBGrid1.Height;
     footer.Left:=DBGrid1.Left;
     footer.Width:=dbgrid1.Width;
     footer.Panels.Add;
     footer.Panels.Items[0].Width:=11;
     for I := 1 to DBGrid1.Columns.Count-1  do
     begin
        footer.Panels.Add;
        footer.Panels.Items[i].Width:=DBGrid1.Columns.Items[i-1].Width+2;
     end;
     fin:=0;
     colfin:=0;
end;

Y El DrawColumnCell
Código Delphi [-]
procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
  DataCol: Integer; Column: TColumn; State: TGridDrawState);
  var i:integer;
begin
    if fin=0 then
    begin
       fin:=1;
       colini:=Column.ID;
    end;
    if column.id>Colfin then colfin:=Column.ID;

     if (DBGrid1.DataSource.DataSet.RecNo=DBGrid1.DataSource.DataSet.RecordCount)
        and
        (Column.ID=colfin) then//Saber si estamos en la última fila visible
     begin
//             
             for I := 0 to footer.Panels.Count -1  do  //AQUI DA EL FALLO
              begin
                  if (i>=(colini))and(i<=(Colfin)) then
                  begin
                    footer.Panels.Items[i].Width:=DBGrid1.Columns.Items[i].Width;
                    footer.Panels.Items[i].Text:=IntToStr(Column.ID);

                  end else Footer.Panels.Items[i].Width:=0;

              end;
              
              fin:=0;
     end;
end;

José Luis Garcí 22-11-2009 10:46:55

Resuelto, el problema era que declaraba footer, tanto en las variables generales del form y luego lo repetía declarándolo en el OnCreate del Form


Código Delphi [-]
var
  Form1: TForm1;
  footer:tstatusbar;
  fin, Colfin,colini: integer;


Código Delphi [-]
procedure TForm1.FormCreate(Sender: TObject);
var footer:tstatusbar;
  i:integer;
begin

Elimine este último y funciono, ahora me toca pelearme con otras partes del código.


La franja horaria es GMT +2. Ahora son las 23:19:13.

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