function DBGridAutoSize(mDBGrid: TDBGrid; mOffset: Integer = 5): Boolean;<br>{ 返回?据网格自?适??度是否成功 }<br>var<br>I: Integer;<br>begin<br>Result := False;<br>if not Assigned(mDBGrid) then Exit;<br>if not Assigned(mDBGrid.DataSource) then Exit;<br>if not Assigned(mDBGrid.DataSource.DataSet) then Exit;<br>if not mDBGrid.DataSource.DataSet.Active then Exit;<br>for I := 0 to mDBGrid.Columns.Count - 1 do begin<br>if not mDBGrid.Columns.Visible then Continue;<br>if Assigned(mDBGrid.Columns.Field) then<br>mDBGrid.Columns.Width := Max(mDBGrid.Columns.Field.Tag,<br>mDBGrid.Canvas.TextWidth(mDBGrid.Columns.Title.Caption)) + mOffset<br>else mDBGrid.Columns.Width :=<br>mDBGrid.Canvas.TextWidth(mDBGrid.Columns.Title.Caption) + mOffset;<br>mDBGrid.Refresh;<br>end;<br>Result := True;<br>end; { DBGridAutoSize }