.DFM 文件更改的原因是因为两台机器之间的 Windows 注册表设置存在一些差异
计算机\HKEY_CURRENT_USER\控制面板\桌面\WindowMetrics
这导致边框、标题、表单标题高度/宽度不同
如果您使用相同的 exe 运行以下函数,您可能会得到不同的结果
高度计算
//这将获取表单标题高度
GetSystemMetrics( SM_CYCAPTION )
//这将获取表单边框宽度
GetSystemMetrics(SM_CYFRAME)
//这将获取表单主菜单高度
GetSystemMetrics(SM_CYMENU)
这是一个示例函数,用于显示高度计算的分解
function CalcHeightDifference : String;
var iActualHeightDifference : integer;
iCalcHeightDifference : integer;
sInfo : String;
begin
iCalcHeightDifference := 0;
iActualHeightDifference := self.Height - Self.ClientHeight;
//Caption
iCalcHeightDifference := iCalcHeightDifference + GetSystemMetrics( SM_CYCAPTION );
sInfo := ' + Form Caption = ' + inttostr( GetSystemMetrics( SM_CYCAPTION ) );
//Borders
iCalcHeightDifference := iCalcHeightDifference + GetSystemMetrics( SM_CYFRAME) + GetSystemMetrics( SM_CYFRAME);
sInfo := sInfo + sLineBreak + ' + Border Height(' + inttostr( GetSystemMetrics( SM_CYFRAME)) + ') times two = ' + inttostr( GetSystemMetrics( SM_CYFRAME)+GetSystemMetrics( SM_CYFRAME) );
//Menu
if self.Menu <> nil then begin
iCalcHeightDifference := iCalcHeightDifference + GetSystemMetrics(SM_CYMENU);
sInfo := sInfo + sLineBreak + ' + Form MainMenu = ' + inttostr( GetSystemMetrics(SM_CYMENU) );
end;
result := format( 'Form.ClientHeight=%d', [Self.ClientHeight])
+ sLineBreak
+ format('Form.Height=%d', [Self.Height])
+ sLineBreak
+ format('The Height Difference of %d is made up of', [Self.Height-Self.ClientHeight])
+ sLineBreak
+ sInfo
+ sLineBreak
+ format(' Total( %d )', [iCalcHeightDifference]) ;
end;
宽度计算
//这将获取表单边框宽度
GetSystemMetrics(SM_CXFRAME)
这是一个示例函数,用于显示宽度计算的分解
function CalcWidthDifference : String;
var iActualWidthDifference : integer;
iCalcWidthDifference : integer;
sInfo : String;
begin
iCalcWidthDifference := 0;
iActualWidthDifference := self.Width - Self.ClientWidth;
//Borders
iCalcWidthDifference := GetSystemMetrics( SM_CXFRAME) + GetSystemMetrics( SM_CXFRAME);
sInfo := ' + Border Width(' + inttostr( GetSystemMetrics( SM_CXFRAME) ) + ') times Two = ' + inttostr( GetSystemMetrics( SM_CXFRAME)+GetSystemMetrics( SM_CXFRAME) );
result := format( 'Form.ClientWidth=%d', [Self.ClientWidth])
+ sLineBreak
+ format('Form.Width=%d', [Self.Width])
+ sLineBreak
+ format('The Width Difference of %d is made up of', [Self.Width-Self.ClientWidth])
+ sLineBreak
+ sInfo
+ sLineBreak
+ format(' Total( %d )', [iCalcWidthDifference]) ;
end;
这一切都是因为我们有两台 Windows 开发机器,它们随机更改表单和面板等上 .DFM 文件的宽度
我在下面包含了一些从不同机器上的相同 exe 运行的屏幕截图,以显示宽度不同。如果我要在设计时更改该表单上的某些内容,.dfm 文件将以不同的宽度保存
机器 1
机2