A client with a successful Delphi 7 application recently got in touch for some updates. While working on the project, I've noticed again something that has long bugged me.
Oftentimes simply opening and viewing a VCL form reveals git changes like the following at check-in:
- ItemHeight = 25
+ ItemHeight = 0
At other times, it might be the other way round:
- ItemHeight = 0
+ ItemHeight = 19
Usually there are no changes in ItemHeight
fields.
This appears to only affect TComboBox
controls. The Height
of TComboBox
controls is determined by its' font's Height
and other properties. As far as I can tell, it doesn't matter whether I check in the change or revert - the exact same behaviour is displayed at runtime. Reverting the changes is what I typically do, but this is tedious if there are dozens of them.
There is no discernible pattern as to whether or where changes will happen, and if they do which way the changes will go. Often the switch happens on TComboBox
controls in areas or on TTabSheet
pages that were never even viewed.
Note: No subtantive modifications are being made in the IDE to the form, except perhaps to the odd TPageControl.ActivePage
property or a minor change like adding a TLabel
.
My questions are related:
Is there a way to prevent these "noise" changes in the history?
Not that I am aware of.
Is this a bug in Delphi 7 which is resolved in later versions of Delphi and the VCL?
No. It is caused by the fact that ItemHeight
is retrieved by a message which returns 0 when no handle is allocated. This is documented in the source:
function TCustomComboBox.GetItemHt: Integer;
begin
if FStyle in [csOwnerDrawFixed, csOwnerDrawVariable] then
Result := FItemHeight
else
Result := Perform(CB_GETITEMHEIGHT, 0, 0); // returns 0 if Handle = 0
end;
If the control is not visible during design (f.i. because it is located on an inactive tab sheet), it is most likely that the handle is 0.