Ver Mensaje Individual
  #2  
Antiguo 07-11-2008
[coso] coso is offline
Miembro Premium
 
Registrado: may 2008
Ubicación: Girona
Posts: 1.678
Reputación: 0
coso Va por buen camino
Hola, seria algo asi:

Código Delphi [-]
var
     q : TADOQuery;
     w : integer;
     i : integer;
     k : integer;
begin
     q := TADOQUery.Create(self);
     q.Connection := ADOConnection1;
     q.Active := false;
     q.SQL.Text := 'select * from tabla';
     q.Active := true;
     q.First;
     w := 0;
     while not q.Eof do
     begin
          k := length(q.FieldByName('CAMPO').Asstring);
          if k > w then w := k;
          q.Next;
     end;
     DBGrid1.Columns[1].Width := DBGrid1.Canvas.TextWidth('X')*w;
end;

Aunque en teoria, esto tendria que funcionar (a mi no me lo ha hecho pues no me reconoce la funcion length, aunque existe en sql en general)

Código Delphi [-]
q.Active := false;
q.SQL.Text := 'select max(length(CAMPO)) as max_len from tabla';
q.Active := true;
 
DBGrid1.Columns[1].Width := DBGrid1.Canvas.TextWidth('X')*q.FieldByName('MAX_LEN').Asinteger;
Responder Con Cita