Fix too narrow column widths restored with high DPI setting, due to Delphi's Round() function using the nearest *even* number. Use the better suited "kaufmännisch runden" approach.

This commit is contained in:
Ansgar Becker
2022-11-30 21:12:00 +01:00
parent 7bea342b9f
commit 78dd4c2bd2
2 changed files with 17 additions and 4 deletions

View File

@@ -300,6 +300,7 @@ type
function DeleteFileWithUndo(sFileName: String): Boolean;
function MakeInt(Str: String) : Int64;
function MakeFloat(Str: String): Extended;
function RoundCommercial(e: Extended): Int64;
function CleanupNumber(Str: String): String;
function IsInt(Str: String): Boolean;
function IsFloat(Str: String): Boolean;
@@ -730,6 +731,16 @@ begin
end;
function RoundCommercial(e: Extended): Int64;
begin
// "Kaufm<66>nnisch runden"
// In contrast to Delphi's Round() which rounds *.5 to the next even number
Result := Trunc(e);
if Frac(e) >= 0.5 then
Result := Result + 1;
end;
{***
SynEdit removes all newlines and semi-randomly decides a
new newline format to use for any text edited.

View File

@@ -210,7 +210,8 @@ end;
}
class procedure TExtForm.SaveListSetup( List: TVirtualStringTree );
var
i, ColWidth: Integer;
i: Integer;
ColWidth: Int64;
ColWidths, ColsVisible, ColPos, Regname: String;
OwnerForm: TWinControl;
begin
@@ -234,7 +235,7 @@ begin
// Column widths
if ColWidths <> '' then
ColWidths := ColWidths + ',';
ColWidth := Round(List.Header.Columns[i].Width / OwnerForm.ScaleFactor);
ColWidth := RoundCommercial(List.Header.Columns[i].Width / OwnerForm.ScaleFactor);
ColWidths := ColWidths + IntToStr(ColWidth);
// Column visibility
@@ -269,7 +270,8 @@ end;
class procedure TExtForm.RestoreListSetup( List: TVirtualStringTree );
var
i : Byte;
ColWidth, colpos : Integer;
colpos : Integer;
ColWidth: Int64;
Value : String;
ValueList : TStringList;
Regname: String;
@@ -286,7 +288,7 @@ begin
for i := 0 to ValueList.Count - 1 do
begin
ColWidth := MakeInt(ValueList[i]);
ColWidth := Round(ColWidth * OwnerForm.ScaleFactor);
ColWidth := RoundCommercial(ColWidth * OwnerForm.ScaleFactor);
// Check if column number exists and width is at least 1 pixel
if (List.Header.Columns.Count > i) and (ColWidth > 0) and (ColWidth < 1000) then
List.Header.Columns[i].Width := ColWidth;