tstrings property's write method doesn't get called on insert

I had a problem today with one of my components, that didn't
work properly. I found the problem and condensed it to the
code below.

Now that I've found it, I realize that a tstrings property
cannot get partially set (one of the lines) by my set_str
method (str.assign(...)). But where DOES the fstr variable
change? It certainly isn't in set_str.

Please e-mail as well if you reply to the newgroup.

=================================================================
unit sstrbug;
{
This piece of code demonstrates a problem that might occur
when an object has a tstrings property. I wouldn't like to call
it a bug, but it certainly caused me some problems...

The intention is that the tbugdemo.changed variable should be set to
true whenever tbugdemo.str property has changed. This does not
happen when the methods of tstrings is used, such as "insert"
below. When button2 is clicked, checkbox1 remains unchecked.

If you have a solution for this, please e-mail me at
s...@speech.kth.se

Quote
}

interface

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

type tbugdemo=class(tcomponent)
  private
    fstr:tstrings;
    constructor create(aowner:tcomponent);
    destructor destroy;
    procedure set_str(value:tstrings);
  public
    changed:boolean; {intended to reflect changes in property str}
    property str:tstrings read fstr write set_str;
  end;
type
  TForm1 = class(TForm)
    Memo1: TMemo;
    Memo2: TMemo;
    Edit1: TEdit;
    CheckBox1: TCheckBox;
    Button1: TButton;
    Button2: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure CheckBox1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
    str1:tbugdemo;
  end;
var
  Form1: TForm1;

implementation

{$R *.DFM}
constructor Tbugdemo.create(aowner:tcomponent);
begin;
    inherited create(aowner);
    fstr:=tstringlist.create;
    changed:=false;
end;
destructor Tbugdemo.destroy;
begin;
    fstr.free;
    inherited destroy;
end;
procedure Tbugdemo.set_str(value:tstrings);
begin;
    {This method should get called whenever str changes,
     but it does not get called when str property changes
     through tstring methods :-(
     As a consequnce, the "changed" variable is not set to true}
    fstr.assign(value);
    changed:=true;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
    str1:=tbugdemo.create(self);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
    {This works fine... set_str gets called
     and changes str1.changed to true}
    str1.str:=memo1.lines;
    memo2.lines:=str1.str;
    checkbox1.checked:=str1.changed;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
    {This does NOT work... set_str never gets called
     and str1.changed remains unchanged}
    str1.str.insert(0,edit1.text);
    memo2.lines:=str1.str;
    checkbox1.checked:=str1.changed;
end;

procedure TForm1.CheckBox1Click(Sender: TObject);
begin
    {Manually change setting of str.changed}
    str1.changed:=checkbox1.checked;
end;

end.