Potential issue in TListview – does not recognise DisplayFormat for TDateTimeField

  

I worked out a simple example. Display Format works for the CustomerAmount (integer) but not CustomerDate (Tdatetime). it seems TDateTime’s displayFormat is not respected by TListview.
The sample table has 3 fields.
The line showmessage( FDMemTable1.FieldByName(‘CustomerDate’).displaytext ); –> this .DisplayText works even without a GetText event
it displays the Date format ‘dd mmm (ddd)’ correctly.
But when it goes to TListview, it does not use the DisplayText. But the TIntegerField uses the DisplayText correct in TListview, so there’s a difference in how TListview handles .DisplayText for TIntegerField vs TDateTimeField.
type
TForm1 = class(TForm)
ListView1: TListView;
Button1: TButton;
FDMemTable1: TFDMemTable;
BindSourceDB1: TBindSourceDB;
FDMemTable1CustomerID: TIntegerField;
FDMemTable1CustomerName: TStringField;
BindSourceDB2: TBindSourceDB;
BindingsList1: TBindingsList;
FDMemTable1CustomerDate: TDateTimeField;
FDMemTable1CustomerAmount: TIntegerField;
procedure Button1Click(Sender: TObject);
private
FLinkFillControlToField : TLinkFillControlToField;
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.fmx}

procedure TForm1.Button1Click(Sender: TObject);
begin
with FDMemTable1 do
begin
Open;

Append;
FieldByName(‘CustomerID’).AsInteger := 1;
FieldByName(‘CustomerAmount’).AsInteger := 1250000;
FieldByName(‘CustomerName’).AsString := ‘ABC’;
FieldByName(‘CustomerDate’).AsDateTime := NOW();
Post;

Append;
FieldByName(‘CustomerID’).AsInteger := 2;
FieldByName(‘CustomerAmount’).AsInteger := 2550000;
FieldByName(‘CustomerName’).AsString := ‘XYZ’;
FieldByName(‘CustomerDate’).AsDateTime := NOW()+1;
Post;

Append;
FieldByName(‘CustomerID’).AsInteger := 3;
FieldByName(‘CustomerAmount’).AsInteger := 3250000;
FieldByName(‘CustomerName’).AsString := ‘XYZ’;
FieldByName(‘CustomerDate’).AsDateTime := NOW()+2;
Post;

(FDMemTable1.FieldByName(‘CustomerAmount’) as TIntegerField).DisplayFormat
:= ‘#,###,###’;
(FDMemTable1.FieldByName(‘CustomerDate’) as TDateTimeField).DisplayFormat
:= ‘dd yyyy (ddd)’;
end;

showmessage( FDMemTable1.FieldByName(‘CustomerDate’).displaytext );
// this .DisplayText works but not below

if not Assigned(FLinkFillControlToField) then
begin
FLinkFillControlToField := TLinkFillControlToField.Create(BindingsList1);
FLinkFillControlToField.Control := listview1;

with FLinkFillControlToField do
begin
Category := ‘Quick Bindings’;
Track := False;
Direction := linkDataToControl;
AutoActivate := False;
AutoFill := True;
BindSourceDB1.DataSource.Enabled := True;
FillDataSource := BindSourceDB1;
end;
end;

with FLinkFillControlToField do
begin
FillHeaderFieldName := ‘CustomerName’;

with FillExpressions.AddExpression do
begin
//SourceMemberName := ‘CustomerID’;
SourceMemberName := ‘CustomerAmount’;
ControlMemberName := ‘Text1’;
end;
with FillExpressions.AddExpression do
begin
SourceMemberName := ‘CustomerDate’;
ControlMemberName := ‘Text2’;
end;
end;
FLinkFillControlToField.Active := True;
end;

object Form1: TForm1
Left = 0
Top = 0
Caption = ‘Form1’
ClientHeight = 404
ClientWidth = 763
FormFactor.Width = 320
FormFactor.Height = 480
FormFactor.Devices = [Desktop]
DesignerMasterStyle = 0
object ListView1: TListView
ItemAppearanceClassName = ‘TDynamicAppearance’
ItemEditAppearanceClassName = ‘TDynamicAppearance’
HeaderAppearanceClassName = ‘TListHeaderObjects’
FooterAppearanceClassName = ‘TListHeaderObjects’
Position.X = 16.000000000000000000
Position.Y = 24.000000000000000000
Size.Width = 561.000000000000000000
Size.Height = 353.000000000000000000
Size.PlatformDefault = False
ItemAppearanceObjects.ItemObjects.ObjectsCollection = <
item
AppearanceObjectName = ‘Text1’
AppearanceClassName = ‘TTextObjectAppearance’
Appearance.Width = 223.000000000000000000
Appearance.Height = 44.000000000000000000
end
item
AppearanceObjectName = ‘Text2’
AppearanceClassName = ‘TTextObjectAppearance’
Appearance.Width = 208.000000000000000000
Appearance.Height = 44.000000000000000000
Appearance.PlaceOffset.X = 326.000000000000000000
end>
ItemAppearanceObjects.ItemEditObjects.ObjectsCollection = <
item
AppearanceObjectName = ‘Text1’
AppearanceClassName = ‘TTextObjectAppearance’
end>
end
object Button1: TButton
Position.X = 592.000000000000000000
Position.Y = 24.000000000000000000
Size.Width = 161.000000000000000000
Size.Height = 57.000000000000000000
Size.PlatformDefault = False
Text = ‘Button1’
OnClick = Button1Click
end
object FDMemTable1: TFDMemTable
FetchOptions.AssignedValues = [evMode]
FetchOptions.Mode = fmAll
ResourceOptions.AssignedValues = [rvSilentMode]
ResourceOptions.SilentMode = True
UpdateOptions.AssignedValues = [uvCheckRequired, uvAutoCommitUpdates]
UpdateOptions.CheckRequired = False
UpdateOptions.AutoCommitUpdates = True
Left = 576
Top = 128
object FDMemTable1CustomerID: TIntegerField
FieldName = ‘CustomerID’
end
object FDMemTable1CustomerName: TStringField
FieldName = ‘CustomerName’
Size = 30
end
object FDMemTable1CustomerDate: TDateTimeField
FieldName = ‘CustomerDate’
end
object FDMemTable1CustomerAmount: TIntegerField
FieldName = ‘CustomerAmount’
end
end
object BindSourceDB1: TBindSourceDB
DataSet = FDMemTable1
ScopeMappings = <>
Left = 576
Top = 192
end
object BindSourceDB2: TBindSourceDB
DataSet = FDMemTable1
ScopeMappings = <>
Left = 576
Top = 248
end
object BindingsList1: TBindingsList
Methods = <>
OutputConverters = <>
Left = 20
Top = 5
end
end

Comments are closed.