Redeclare Width property for Delphi custom component

I have a custom Delphi component going down from TGraphicControl. Its class is declared as follows:

TMyLabel = class(TGraphicControl)
private
  ...
protected
  ...
public
  ...
published
  property Height;
  property Width write SetWidth;
  ...
end;

The implementation of SetWidth is as follows:

procedure TMyLabel.SetWidth(const Value: Integer);
begin
  if (Value >= 0) and (Value <> Width)
  then begin
    inherited Width := Value;
    // Do some other stuff
    ...
  end;
  MessageDlg('Test', mtInformation, [mbOK], 0);
end;

I am currently getting SetWidth when the width of a component changes programmatically at run time or at design time by entering a value in the corresponding field of the object inspector. However, when I resize the component during development with the mouse, the inspector field for the Width object updates, but the message box does not appear, so my SetWidth procedure is not called.

, SetWidth , Paint, , ( ). ?

+3
3

, .

, "" , SetWidth . - Width, . .

var Control: TControl;
begin
 Control := MyLabel;
 Control.Width := 5000; // TMyLabel.SetWidth is not called!!

: Width , Deltics . TControl.SetBounds.

var MyLabel: TMyLabel;
begin
 MyLabel.SetBounds(0, 0, 100, 100); // TMyLabel.SetWidth nor TControl.SetWidth is called!!

, . TControl.CanResize, . , , TControl.Resize.

+6

, , SetBounds(), , , .

, SetBounds() , .

+6

Width, read, write, Object Inspector. , :

procedure TMyLabel.GetWidth: Integer;
begin
  result := inherited Width;
end;
+4
source

Source: https://habr.com/ru/post/1776346/


All Articles