Board logo

Subject: [cnpack\cnvcl\Examples\AutoOption的TStringlist]Help [Print This Page]

Author: f00l    Time: 2009-6-3 14:54     Subject: [cnpack\cnvcl\Examples\AutoOption的TStringlist]Help

cnpack\cnvcl\Examples\AutoOption的Demo。
在MyClass1里加了属性
private
    Fsl : TStringList;
    procedure Setsl(Asl: TStringList);
published
    constructor Create();
    property sl: TStringList read Fsl write Setsl;

constructor TMyClass1.Create;
begin
  Fsl := TStringList.Create;
  Fsl.Add('a');
  Fsl.Add('b');
end;

procedure TMyClass1.Setsl(Asl: TStringList);
begin
  ShowMessage('Setting');
end;

我是SBT.T为啥Apply以后Setls不起作用而是直接更改sl呢0.0
是不是小生犯了原则 Sex 问题0.0
Author: Passion    Time: 2009-6-3 15:26

估计代码里头是直接处理的sl.Add或sl.Text :=,用这方式赋值的。
这样赋值是不会调用SetSl的,而只会直接使用Fsl这对象来进行操作。
Author: Passion    Time: 2009-6-3 15:29

测试代码,点击btnSet时,不会触发Set事件:

unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    btnSet: TButton;
    btnShow: TButton;
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure btnSetClick(Sender: TObject);
    procedure btnShowClick(Sender: TObject);
  private
    FList: TStringList;
    procedure SetList(const Value: TStringList);
    { Private declarations }
  public
    { Public declarations }
    property List: TStringList read FList write SetList;
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.FormCreate(Sender: TObject);
begin
  FList := TStringList.Create;
  List.Add('aaa');
end;

procedure TForm1.SetList(const Value: TStringList);
begin
  ShowMessage('Set 了');
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
  FList.Free;
end;

procedure TForm1.btnSetClick(Sender: TObject);
begin
  List.Text := 'xxxxxxx';
  List.Add('bbbbbb');
end;

procedure TForm1.btnShowClick(Sender: TObject);
begin
  ShowMessage(List.Text);
end;

end.




Welcome to CnPack Forum (http://bbs.cnpack.org/) Powered by Discuz! 5.0.0