我的这段就是动态产生的DisplayFormat,拿去用吧:
procedure TdmData.UpdateFieldFormats(DataSet: TDataSet);
const
defFloatFormat: string = ',0.00';
defDateFormat: string = 'yyyy-mm-dd';
defTimeFormat: string = 'hh:mm:ss';
defDateTimeFormat: string = 'yyyy-mm-dd hh:mm:ss';
var
I: Integer;
begin
for I := 0 to DataSet.FieldCount - 1 do begin
case DataSet.Fields.DataType of
ftFloat, ftCurrency, ftBCD:
begin
TNumericField(DataSet.Fields).DisplayFormat := defFloatFormat;
TNumericField(DataSet.Fields).EditFormat := '#.##';
end;
ftDate: TDateTimeField(DataSet.Fields).DisplayFormat := defDateFormat;
ftTime: TDateTimeField(DataSet.Fields).DisplayFormat := defTimeFormat;
ftDateTime: TDateTimeField(DataSet.Fields).DisplayFormat := defDateTimeFormat;
end;
end;
end;