[DUG] ClientDataSet TField Display Format
Colin Johnsun
colin.adug at gmail.com
Wed Nov 2 01:35:04 NZDT 2011
Hi John,
Don't use AsString property, instead use the DisplayText property.
The DisplayText property make use of the DisplayFormat settings.
Hope this helps,
Cheers,
Colin
On 1 November 2011 22:48, John Bird <johnkbird at paradise.net.nz> wrote:
> I am wishing to use a ClientDataSet for custom data, not read from a
> database, and with varying formats. This means that field definitions and
> populating it are all done at run time.
>
> The data has some integer values that are 8 digit dates, and some that are
> IRD numbers and I want to format them to show in controls – eg IRD numbers
> as 10-000-033 for example.
>
> The code I am using below does work fine for displaying data on the screen,
> but not for printing – the printing line in the report (Rave D2007) uses a
> line in a loop like:
>
> ThisField:=lDBGrid.Columns[colptr].Field;
> if not ThisField.IsNull then lText:=lDBGrid.Fields[colptr].asString;
>
> But getting the value asString does not get the Display format – i get
> 10000033 for example, so pretty useless for a report.
>
> Anyone have an idea what more I can do to get the printing also use the
> DisplayFormat ?
>
>
> Below is how I create the Dataset.
>
> (Eventually I would like to add some events to reformat the integer dates,
> so that instead of displaying as YYYY-MM-DD they can be displayed as
> DD-MM-YYYY but I am not sure that is possible – so first things first).
>
>
>
> ClientDataSet1.Fields.Clear;
> with ClientDataSet1 do
> begin
> with TIntegerField.Create(Self) do
> begin
> Name := 'ClientDataSet1RNO';
> FieldKind := fkData;
> FieldName := 'RNO';
> DataSet := ClientDataSet1;
> end; //FieldName
> with TStringField.Create(Self) do
> begin
> Name := 'ClientDataSet1Alpha1';
> FieldKind := fkData;
> FieldName := 'Alpha1';
> Size := 10;
> DataSet := ClientDataSet1;
> end; //FieldName
> with TDateField.Create(Self) do
> begin
> Name := 'ClientDataSet1Date1';
> FieldKind := fkData;
> FieldName := 'Date1';
> DataSet := ClientDataSet1;
> end; //FieldName
> with TFloatField.Create(Self) do
> begin
> Name := 'ClientDataSet1Float1';
> FieldKind := fkData;
> FieldName := 'Float1';
> DataSet := ClientDataSet1;
> end; //FieldName
> with TIntegerField.Create(Self) do
> begin
> Name := 'ClientDataSet1DDate1';
> FieldKind := fkData;
> FieldName := 'DDate1';
> DataSet := ClientDataSet1;
> end; //FieldName
> with TIntegerField.Create(Self) do
> begin
> Name := 'ClientDataSetCLIRD1';
> FieldKind := fkData;
> FieldName := 'CLIRD1';
> DataSet := ClientDataSet1;
> end; //FieldName
> end;
>
>
> TIntegerField(ClientDataSet1.FieldByName('CLIRD1')).DisplayFormat :=
> '000-000-000';
> TIntegerField(ClientDataSet1.FieldByName('DDate1')).DisplayFormat :=
> '0000-00-00';
>
> TIntegerField(ClientDataSet1.FieldByName('CLIRD1')).EditFormat := '#';
>
> ClientDataset1.CreateDataset;
>
>
>
> John Bird
>
> _______________________________________________
> NZ Borland Developers Group - Delphi mailing list
> Post: delphi at listserver.123.net.nz
> Admin: http://delphi.org.nz/mailman/listinfo/delphi
> Unsubscribe: send an email to delphi-request at listserver.123.net.nz with
> Subject: unsubscribe
>
More information about the Delphi
mailing list