我有一个 TListView 和一个 TObjectList。我将 TFoo.value 绑定到 Item.Caption。我写了一个程序“AfterScroll”,里面有一个显示消息。我在 TBindSourceAdapter.AfterScroll 上连接程序。
我运行这个程序,我只有一个显示消息。
如果我用 TStringGrid 替换 TListView,我在每一行都有显示消息。
type
TFoo = class
private
FValue: string;
public
constructor create(sValue: string);
property Value: string read FValue write FValue;
end;
TForm5 = class(TForm)
PrototypeBindSource1: TPrototypeBindSource;
StringGrid1: TStringGrid;
BindingsList1: TBindingsList;
LinkGridToDataSourcePrototypeBindSource1: TLinkGridToDataSource;
ListView1: TListView;
LinkFillControlToField1: TLinkFillControlToField;
procedure PrototypeBindSource1CreateAdapter(Sender: TObject; var ABindSourceAdapter: TBindSourceAdapter);
private
{ Déclarations privées }
ListFoo: TObjectList<TFoo>;
procedure AfterScrool(Adapter: TBindSourceAdapter);
public
{ Déclarations publiques }
constructor create(AOwner: TComponent); override;
end;
var
Form5: TForm5;
implementation
{$R *.fmx}
{ TForm5 }
procedure TForm5.AfterScrool(Adapter: TBindSourceAdapter);
begin
ShowMessage('kk');
end;
constructor TForm5.create(AOwner: TComponent);
begin
ListFoo := TObjectList<TFoo>.create();
ListFoo.Add(TFoo.create('Test'));
ListFoo.Add(TFoo.create('Test 1'));
ListFoo.Add(TFoo.create('Test 2'));
ListFoo.Add(TFoo.create('Test 3'));
inherited create(AOwner);
end;
procedure TForm5.PrototypeBindSource1CreateAdapter(Sender: TObject; var ABindSourceAdapter: TBindSourceAdapter);
begin
ABindSourceAdapter := TListBindSourceAdapter<TFoo>.create(self, ListFoo);
ABindSourceAdapter.AfterScroll := AfterScrool;
end;
{ TFoo }
constructor TFoo.create(sValue: string);
begin
inherited create;
FValue := sValue;
end;
end.
可以在 TListView 上连接“AfterScroll”事件吗?