I am trying to make a frame with a DBGrid that will serve for more than 10 tables with half of its fields as defaults, and other fields exclusive for each table
Why to use so complicated code? :D Just use this. Its also have 5 px offset.
procedure TForm1.FormActivate(Sender: TObject);
var
i:integer;
begin
for i :=0 to DbGrid1.Columns.Count - 1 do
DbGrid1.Columns[i].width :=5+dbgrid1.Canvas.TextWidth(DbGrid1.Columns[i].Title.Caption);
end;