## Need some Math help please

## Need some Math help please

(OP)

Hi All, I have a DBGrid with 6-Columns and Widths of 30, 30, 50,130, 130, 130. When I make the Main Form wider or narrower, I want to keep the Column Widths proportional. I am at the limit of my Math skills and this is not working at all well. Can someone please tell me how to do this. There seems to be a Rounding problem as I keep getting varying white-space to the right of the last column.

#### CODE

procedure SetColumnWidths; var i : Integer; aPcnt : Real; aWid : Real; anInc : Integer; Smaller : Boolean; begin if aClientWidth = ClientWidth then Exit; Smaller:=aClientWidth > ClientWidth; aPcnt:=(((aClientWidth-ClientWidth) / ClientWidth) * 100.0); for i:=0 to dbgridItems.Columns.Count-1 do begin aWid:=dbgridItems.Columns[i].Width; anInc:=Abs(Round(aWid * aPcnt / 100.0)); if Smaller then dbgridItems.Columns[i].Width:=dbgridItems.columns[i].Width-anInc else dbgridItems.Columns[i].Width:=dbgridItems.columns[i].Width+anInc; end; aClientWidth:=ClientWidth; aClientHeight:=ClientHeight; end;

## RE: Need some Math help please

## CODE

Of course, you want to take the farthest left space into account, too. But this seems to work for me (except for the white space the controls always seem to produce when you size a part to the same dimension as the parent control).

It is not possible for anyone to acknowledge truth when their salary depends on them not doing it.

## RE: Need some Math help please

In the interim, I finished up doing something similar, albeit, almost by brute-force. Your approach is much more elegant so will use that with very grateful thanks for the help.

Dave