Board index » delphi » property of form <> property of component

property of form <> property of component

Look at following small unit,
question and comments at the bottom!
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
Dialogs,
  StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    procedure FormDblClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    FIntValue: integer;
    procedure SetIntValue(const Value: integer);
    { Private declarations }
  public
    property IntValue: integer read FIntValue write SetIntValue;
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

{ TForm1 }

procedure TForm1.SetIntValue(const Value: integer);
begin
  FIntValue := Value;
  caption := IntToStr(FIntValue);
end;

procedure TForm1.FormDblClick(Sender: TObject);
begin
  Inc(FIntValue);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  IntValue := 13;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  button1.Caption := IntToStr(IntValue);
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  IntValue := IntValue +1;

end;

end.

Look at the double click on the form. It doesn't fire SetIntValue !
Why is this ? Feature or bug ? (In delphi 5)
If you would have the same
    property IntValue: integer read FIntValue write SetIntValue;
in a component, correct me if I'm wrong but I always thougt if you
change FIntValue as a private var in one of the procedure of a
component, the SetInValue procedure is also fired !

 

Re:property of form <> property of component


Quote
Marc Convents wrote:
> Look at following small unit,
> question and comments at the bottom!

> Look at the double click on the form. It doesn't fire SetIntValue !
> Why is this ? Feature or bug ? (In delphi 5)
> If you would have the same
>     property IntValue: integer read FIntValue write SetIntValue;
> in a component, correct me if I'm wrong but I always thougt if you
> change FIntValue as a private var in one of the procedure of a
> component, the SetInValue procedure is also fired !

Marc,

No, writing directly to FIntValue will not fire off the SetIntValue
method in either a form or a component.

Regards,
Scott

Re:property of form <> property of component


Hey ! You're right, as following demo component shows.
Pressing '2' changes FUpperText, without passing by SetUpperText.
Pressing '3' shows current value of FUpperText
Pressing '1' shows the changing of UpperText, with SetUpperText.
(Just for educating reasons)

unit EditTry;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
Dialogs,
  StdCtrls;

type
  TEditTry = class(TEdit)
  private
    FUpperText: string;
    procedure SetUpperText(const Value: string);
    { Private declarations }
  protected
    procedure KeyPress(var Key: Char); override;
  public
    { Public declarations }
  published
    property upperText: string read FUpperText write SetUpperText;
  end;

implementation

{ TEditTry }

procedure TEditTry.KeyPress(var Key: Char);
begin
  if key='1' then
  begin
    key:=#0;
    FUpperText := 'UPPERCASE';
  end
  else if key='2' then
  begin
    key:=#0;
    UpperText := 'UPPERCASE';
  end
  else if key='3' then
  begin
    key:=#0;
    showmessage(FUpperText)
  end
  else
   inherited;

end;

procedure TEditTry.SetUpperText(const Value: string);
begin
  FUpperText := uppercase(Value);
  Text := FUpperText;
end;

end.

Other Threads