TMaskEdit shrinking width issue in Delphi 7 IDE

Viewed 95

I noticed a strange behavior about the VCL's TMaskEdit component.

When you change the EditMask property's value at design-time, the control's Width reduces by 1 pixel.

Easy to reproduce, drop a TMaskEdit on a Form at design-time and change the EditMask value in the Object Inspector. I repeatedly changed the value to '9' and '0' until the Width went to zero.

The problem does not exist at runtime.

Is it a known problem, and is there a solution? I have a TCustomMaskEdit descendant component and I would love to get rid of this issue.

update: after some investigation I found the problematic code here: TCustomMaskEdit.SetCursor.

This is where the "magic" happens:

for I := Low(NewKeyState) to High(NewKeyState) do
  NewKeyState[I] := 0;
NewKeyState [VK_SHIFT] := $81;
NewKeyState [ArrowKey[UseRightToLeftAlignment]] := $81;
SetKeyboardState(NewKeyState);
FSettingCursor := True;
try
  SendMessage(Handle, WM_KEYDOWN, ArrowKey[UseRightToLeftAlignment], 1);
  SendMessage(Handle, WM_KEYUP, ArrowKey[UseRightToLeftAlignment], 1);
finally
  FSettingCursor := False;
end;

As much as I understand it emulates SHIFT + LEFT, but in design-time it will be handled by the IDE, this causes the control resize.

As a workaround solution I changed my component's ancestor to TCustomMaskEdit, haven't published the EditMask property, and in the code where this property changes I save and restore the Width. Not a nice way, but unfortunately the SetCursor is not virtual, so I can't override to do nothing in design-time.

0 Answers
Related