使用 Delphi Seattle,我试图在我们当前的项目中掌握实时绑定的窍门,并创建了一个带有外部填充 TFDMemTable 的表单。memTable 连接到 TGrid 和 TListbox。网格按应有的方式显示所有信息,但列表框保持空白。
我究竟做错了什么?
代码(根据实际情况进行了简化,但仍然显示空列表框):
unit Unit1;
interface
uses
System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants, System.Rtti, FireDAC.Stan.Intf,
FireDAC.Stan.Option, FireDAC.Stan.Param, FireDAC.Stan.Error, FireDAC.DatS, FireDAC.Phys.Intf, FireDAC.DApt.Intf,
FireDAC.Stan.StorageBin, Data.Bind.EngExt, Fmx.Bind.DBEngExt, Fmx.Bind.Grid, System.Bindings.Outputs,
Fmx.Bind.Editors, Data.Bind.Components, Data.Bind.Grid, FMX.ListBox, Data.Bind.DBScope, Data.DB, FireDAC.Comp.DataSet,
FireDAC.Comp.Client, FMX.Layouts, FMX.Grid, FMX.Types, FMX.Controls, FMX.Controls.Presentation, FMX.StdCtrls,
FMX.Forms;
type
TForm1 = class(TForm)
fdmAccounts: TFDMemTable;
fdmAccountscode: TStringField;
fdmAccountsdesc: TStringField;
bsAccounts: TBindSourceDB;
Grid1: TGrid;
BindingsList1: TBindingsList;
ListBox1: TListBox;
LinkGridToDataSourcebsAccounts: TLinkGridToDataSource;
LinkFillControlToField1: TLinkFillControlToField;
procedure FormCreate(Sender: TObject);
private
FItemlist: TStringlist;
procedure Refreshlist(Sender: TObject);
procedure UpdateAccounts(afilter: string);
end;
var
Form1: TForm1;
implementation
{$R *.fmx}
procedure TForm1.UpdateAccounts(aFilter: string);
var
s: string;
begin
with fdmAccounts do
begin
EmptyDataSet;
for s in FItemList do
begin
if aFilter.IsEmpty or s.Contains(aFilter) then
InsertRecord([s, '']);
end;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
FItemlist := TStringList.Create;
FItemlist.Delimiter := ',';
Fitemlist.DelimitedText := 'item1, item2, ander item3, laatste item';
fdmAccounts.Open;
Refreshlist(nil);
end;
procedure TForm1.Refreshlist(Sender: TObject);
begin
UpdateAccounts('');
end;
end.
活绑定定义:
object BindingsList1: TBindingsList
Methods = <>
OutputConverters = <>
Left = 164
Top = 237
object LinkGridToDataSourcebsAccounts: TLinkGridToDataSource
Category = 'Quick Bindings'
DataSource = bsAccounts
GridControl = Grid1
Columns = <>
end
object LinkFillControlToField1: TLinkFillControlToField
Category = 'Quick Bindings'
Control = ListBox1
Track = True
FillDataSource = bsAccounts
FillDisplayFieldName = 'desc'
AutoFill = True
FillExpressions = <>
FillHeaderExpressions = <>
FillBreakGroups = <>
end
结尾
我还尝试将 LinkFillControlToField1 的 FillExpression 设置为:
FillExpressions = <
item
SourceMemberName = 'desc'
ControlMemberName = 'Text'
end>
但结果相同..空列表框