CnPack Forum


 
Subject: [cnpack\cnvcl\Examples\AutoOption的TStringlist]Help
f00l (色舞天姬)
普通灌水员
Rank: 2



UID 40612
Digest Posts 0
Credits 57
Posts 24
点点分 57
Reading Access 10
Registered 2008-6-30
Status Offline
Post at 2009-6-3 14:54  Profile | Blog | P.M. 
[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
Top
Passion (LiuXiao)
管理员
Rank: 9Rank: 9Rank: 9


UID 359
Digest Posts 19
Credits 6838
Posts 3591
点点分 6838
Reading Access 102
Registered 2004-3-28
Status Offline
Post at 2009-6-3 15:26  Profile | Blog | P.M. 
估计代码里头是直接处理的sl.Add或sl.Text :=,用这方式赋值的。
这样赋值是不会调用SetSl的,而只会直接使用Fsl这对象来进行操作。
Top
Passion (LiuXiao)
管理员
Rank: 9Rank: 9Rank: 9


UID 359
Digest Posts 19
Credits 6838
Posts 3591
点点分 6838
Reading Access 102
Registered 2004-3-28
Status Offline
Post at 2009-6-3 15:29  Profile | Blog | P.M. 
测试代码,点击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.
Top
 




All times are GMT++8, the time now is 2024-11-22 06:37

    本论坛支付平台由支付宝提供
携手打造安全诚信的交易社区 Powered by Discuz! 5.0.0  © 2001-2006 Comsenz Inc.
Processed in 0.016285 second(s), 7 queries , Gzip enabled

Clear Cookies - Contact Us - CnPack Website - Archiver - WAP