Jump to content
sjordi

CustomFormat useless?

Recommended Posts

Hi,

I have aTListView hooked to an underlying Database where one of the values is a currency, a price.

My ListView is bound to the DB via a PrototypeBindSource and an adapter to switch from dummy values to the DB content.

In that Prototype field I have the one field set a currency and its CustomFormat property set to #.00

I tried any kind of formatting without success. The format is ignored.

I need 2 decimals, but zeros ( 0 ) are skipped.

No matter what, trailing zeros are ignored.

12 is shown as 12 instead of 12.00

12.6 is shown as 12.6 instead of 12.60

etc

 

Any idea? Should I get that value from the DB and format it as a string myself?
In that case, what's that CustomFormat field worth for?

 

Thanks for any clarification.

Steve 

Share this post


Link to post

Hi,

in Binding expressions Customformat use DisplayText, see image attached. (Still filling DisplayFormat of the fields 😉)  

That's the easiest way, you can also use Format bindingList method but be careful syntax is slightly different the one we use in programs 

 

Capture_1.PNG

Edited by Serge_G

Share this post


Link to post

Euh ben non, il est pas content.

Adding DisplayText is refused. It complains about that info to be unknown.

Also if I right-click on the LinkListControlToField object and edit the expressions, all fields are grayed out and DisplayText is actually shown in the disabled fields (in the dialog box)...

Now where do I specify the format itself, because I guess I still have to do this somewhere?

Thanks

Share this post


Link to post

Hum !

I was convinced my picture explain the whole thing :classic_unsure: 

In my sample (pro app i'm writing) it's work, and description you gave seem to be the same goal. 

I resume : a TListview (live)binded to a BindSourceDB, linked to a Dataset (whatever could it be Firedac, ClientDataset even TProtypeBindSource) fields of this one declared and some, here your currency field, with their DisplayFormat set.

 

Take care one thing, you have to change those 'displaytext' in the FillExpressions collection  

 

one or more picture to see where you encounter difficulties (even a dfm part of the form) should be a good thing :classic_dry:

ie.

  object bndngslst1: TBindingsList
    Methods = <>
    OutputConverters = <>
    Left = 20
    Top = 5
    object LinkListControlToField1: TLinkListControlToField
      Category = 'Liaisons rapides'
      DataSource = bndQFacture
      Control = lvFactures
      FillExpressions = <
        item
          SourceMemberName = 'ANNEE'
          ControlMemberName = 'NumeroFacture'
          CustomFormat = '%s+'#39'-'#39'+DataSet.NUMERO.Text+'#39' ('#39'+DataSet.PART.Text+'#39')'#39
        end
        item
          SourceMemberName = 'NOM'
          ControlMemberName = 'Client'
        end
        item
          SourceMemberName = 'ECHEANCE'
          ControlMemberName = 'Echeance'
          CustomFormat = 'DisplayText+'#39' '#39'+Dataset.MODE_PAIEMENT.Text'
        end
        item
          SourceMemberName = 'MONTANT'
          ControlMemberName = 'Montant'
        end>
      FillHeaderExpressions = <>
      FillBreakGroups = <>
    end
  end

 

 

Share this post


Link to post

Ok I will investigate this in the coming days and come back with success/failure as soon as possible 🙂

 

Share this post


Link to post

Ok that did it...Almost
I probably screwed something somewhere in my steps replicating your instructions.

It works for Windows, iOS and Android but not for macOS-64 where all values are 0.00.

Any idea why? Is the FilleControlToField behaving differently for macOS?


For those facing number formatting

I have a BindSourcePrototype with the field names matching exactly the Database fields linked to the app (via an Adapter).

So in LiveBindings, I hooked it from the Prototype to the TListview.
Then, as suggested, I selected the link between the prototype and listview in the LiveBinding Window.

Then you can edit the link properties  (the TGeneratorFieldDefs property) and set its CustomFormat to DisplayFormat

Then, in the structure window, select the same field in the LinkFillControlToField branch, open the FillExpressions one, select your field (the one to format)

ControlMember and SourceMemberName should be hooked to your field.

But the CustomFormat should be set to Format('%%.2f', %s)

Then it works.

 

Thanks a lot.

Edited by sjordi

Share this post


Link to post

Hi,

Quote

It works for Windows, iOS and Android but not for macOS-64

sounds strange, but I am not an apple owner

1 hour ago, sjordi said:

CustomFormat to DisplayFormat

Hum, you want to say DisplayText ?

1 hour ago, sjordi said:

But the CustomFormat should be set to Format('%%.2f', %s) 

I report, I think about two times https://quality.embarcadero.com/browse/RSP-22962 , this bug. If you want to use the format of livebindings  try to use

Format('%%.2f', 1*value)

 

Edited by Serge_G

Share this post


Link to post
6 hours ago, Serge_G said:
Quote

Hum, you want to say DisplayText ?

 

Yes. Why did I write DisplayFormat? But this didn't change anything though.

 

Quote

 

I report, I think about two times https://quality.embarcadero.com/browse/RSP-22962 , this bug. If you want to use the format of livebindings  try to use


Format('%%.2f', 1*value)

That did it. Funny! Works on macOS now.

Thanks a lot

Crazy bug though.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×