如何解决在 Livebindinds 中编辑记录时更新计算属性
我在 Delphi Pro 10.3.2 中使用 LiveBindings。当您在 Livebindings 中使用 TListBindSourceAdapter 编辑或附加新记录时,计算字段在记录发布之前不会更新。是否可以在编辑/附加记录时更新计算字段?似乎正在将对象属性读入活动记录缓冲区,以便当前对象反映预编辑/附加状态。由于我希望在我的类中包含计算属性和验证代码,因此在发布活动记录之前我无法使用它们(验证代码未反映在下面的示例中)。
这是一个示例项目。
unit Unit1;
interface
uses
System.SysUtils,System.Types,System.UITypes,System.Classes,System.Variants,FMX.Types,FMX.Controls,FMX.Forms,FMX.Graphics,FMX.Dialogs,System.Rtti,FMX.Grid.Style,Data.Bind.Controls,Data.Bind.EngExt,Fmx.Bind.DBEngExt,Fmx.Bind.Grid,System.Bindings.Outputs,Fmx.Bind.Editors,Data.Bind.Components,Data.Bind.Grid,FMX.Layouts,Fmx.Bind.Navigator,FMX.Controls.Presentation,FMX.ScrollBox,FMX.Grid,Data.Bind.ObjectScope,System.Generics.Collections;
type
TPerson = class
private
FFirstName: string;
FLastName: string;
function GetFullName: string;
public
property FirstName: string read FFirstName write FFirstName;
property LastName: string read FLastName write FLastName;
property FullName: string read GetFullName;
end;
TForm1 = class(TForm)
PrototypeBindSource1: TPrototypeBindSource;
StringGrid1: TStringGrid;
NavigatorPrototypeBindSource1: TBindNavigator;
BindingsList1: TBindingsList;
LinkGridToDataSourcePrototypeBindSource1: TLinkGridToDataSource;
procedure PrototypeBindSource1CreateAdapter(Sender: TObject; var
ABindSourceAdapter: TBindSourceAdapter);
private
{ Private declarations }
FList: TList<TPerson>;
FAdapter: TListBindSourceAdapter<TPerson>;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.fmx}
{ TPerson }
function TPerson.GetFullName: string;
begin
Result := FirstName + ' ' + LastName;
end;
procedure TForm1.PrototypeBindSource1CreateAdapter(Sender: TObject; var
ABindSourceAdapter: TBindSourceAdapter);
begin
FList := TList<TPerson>.Create;
FAdapter := TListBindSourceAdapter<TPerson>.Create(Self,FList);
ABindSourceAdapter := FAdapter;
end;
end.
object Form1: TForm1
Left = 0
Top = 0
Caption = 'Form1'
ClientHeight = 480
ClientWidth = 640
FormFactor.Width = 320
FormFactor.Height = 480
FormFactor.Devices = [Desktop]
DesignerMasterStyle = 0
object StringGrid1: TStringGrid
CanFocus = True
ClipChildren = True
Position.X = 168.000000000000000000
Position.Y = 192.000000000000000000
Size.Width = 313.000000000000000000
Size.Height = 177.000000000000000000
Size.PlatformDefault = False
TabOrder = 1
RowCount = 200
Viewport.Width = 293.000000000000000000
Viewport.Height = 152.000000000000000000
end
object NavigatorPrototypeBindSource1: TBindNavigator
Position.X = 184.000000000000000000
Position.Y = 32.000000000000000000
Size.Width = 241.000000000000000000
Size.Height = 25.000000000000000000
Size.PlatformDefault = False
TabOrder = 2
DataSource = PrototypeBindSource1
xRadius = 4.000000000000000000
yRadius = 4.000000000000000000
end
object PrototypeBindSource1: TPrototypeBindSource
AutoActivate = True
Autopost = False
FieldDefs = <
item
Name = 'FirstName'
ReadOnly = False
end
item
Name = 'LastName'
ReadOnly = False
end
item
Name = 'FullName'
ReadOnly = False
CustomFormat = 'Self.Owner.FirstName.Text + '#39' '#39' + Self.Owner.LastName.Text'
end>
ScopeMappings = <>
OnCreateAdapter = PrototypeBindSource1CreateAdapter
Left = 272
Top = 112
end
object BindingsList1: TBindingsList
Methods = <>
OutputConverters = <>
Left = 20
Top = 5
object LinkGridToDataSourcePrototypeBindSource1: TLinkGridToDataSource
Category = 'Quick Bindings'
DataSource = PrototypeBindSource1
GridControl = StringGrid1
Columns = <>
end
end
end
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。