FormatFloat in Livebinding - delphi

I'm currently trying to use XE5 livebindings to bind a TTrackBar.Value property to a TLabel.text property. The TrackBar has a frequency of 0.1. Unfortunately, what I'm finding is that with the binding in place, the label is displaying increments that aren't exactly 0.1.
For example, if I set the livebinding links 'CustomFormat' property to %s+'x', the label will sometimes display the extended float value, so instead of say displaying 0.6, it'll display something like 0.6004874613100 which makes the UI look messy.
I am aware of the FormatFloat routine, but unfortunately this isn't accepted by the CustomFormat field in the link itself.
Is there any way to format the value so it only displays the short version (i.e. 0.6) instead of the extended value? I know I could manually code it in, but I've got several components in a similar situation and I'd like to use livebindings where possible.

You can use something like Format('%%.1f',%s)
See Mike Sutton's answer here on SO: Using Format in a livebindings CustomFormat

Related

Orbeon XForms round-when-formatting="true"

I would like to ask if there is an option for the round-when-formatting="true" parameter combined with digits-after-decimal="0" parameter in Orbeon XForms to use Traditional rounding.
(23.6->24)(22.8->23)(23.2->23)
In the documentation section I see that it uses half to even rounding method.
round-when-formatting="true" is ideal for using rounding only in the view section, because I want the rounding only in the view, the values for the calculations in the bindings must be unrounded.
Right now there is no such option. I agree that using round-to-even() might not be the right choice. Possibly, this was used because this function in XPath 2 allows specifying a precision, while the round() function doesn't. However, this is fixed wth XPath 3. Either way, I entered issue #3226.

Delphi, using numbers in edits

I was wondering if there is a component like the 'edit', but just for numbers so I can use the .value function in my code.
My textbook says I must make a program, that when the user enters a number and clicks the execute button, the results of the functions must be determined.
The functions are: Trunc, round, frac, sqr and sqrt.
I have to enter the value into, what looks like an 'edit', but whenever I use the .value in my code, it gives me an error saying :Undeclared identifier: 'value'. Although it works when I use a 'SpinEdit'.
Forgive me for being really thick, I do have a severe chest and sinus infection with a fairly bad fever, so my mind is somewhere else at the moment.
Thanks!
Oh, and by the way, I have also used the 'MaskEdit' component but it still gives me the same error
For an edit control there is no property named Value, which is what the compiler is telling your. For an edit control the property you need is Text. That's a string containing the contents of the edit control. You'll need to use StrToFloat or TryStrToFloat to convert to a real type.
You can use a masked edit if you like, and validate the input on entry. The TMaskEdit control derives from TCustomEdit, and again the property used for accessing its content is Text and of type string.
Personally I don't like that because I don't think it gives the clearest feedback to users. It's also hard to write a mask for a general floating point value. Myself, I would validate at the point where the program needs to convert from string to real.
Well, since you asked if there is an edit like component for that, I use TMS AdvEdit. It does a very decent job handling integers and floats. If you can afford it, it's really useful.
It has .FloatValue and .IntValue properties for reading and writing the value, and an EditType that specifies what kind of input is accepted.

Delphi TDataSet filter case insensitive not working

I have an application with lots of datasets created at run-time. Some of this datasets are filtered. As filterOptions I've set foCaseInsensitive
dataset.FilterOptions := [foCaseInsensitive];
that means that 'foCaseInsensitive - Ignore case when comparing strings. ' according to Delphi help.
The dataset.filter is changed on user input.
At begging it shows all values:
when user type something is changed:
The problem is that when I'm typing the last character, it shows nothing
Problem does not appear when I'm typing on upper-case
how can I fix this, to show correct the values when user input is only in lower case?
LE: the component is a standard TDataSet from Delphi.
Filter is assigned with 'Like %value_entered%'.
LE1: I'm using a in-house component which has a DataSet property. After I'm setting the filter, I set the property Filtered to true. So, it is a TDataSet property on what I'm talking about.

Delphi FormatFloat and Format functions

I have an application where users can set how values are displayed. The users enter a formatting string and the component uses FormatFloat to display the value.
But now we are using a new third-party component which formats values using the Format function and of course none of our user formats work as the Format & FormatFloat functions use a different syntax.
So does anyone know of a way of converting between the two? Or maybe someone has code to do it?
Thanks,
AJ
Though the format strings for FormatFloat can be more or less transformed to ones for Format, you may only get real similarity for positive values. The Format method simply doesn't offer enough flexibility to incorperate the features and fine-grained control that the format strings for the FormatFloat method offers.
For example, the FormatFloat method allows for three different formats for positive, negative and zero values. Also, the FormatFloat format strings allow for string literals, e.g. '#,##0.00;;Zero'; (which means that zero values are printed as "Zero").
To get something similar using the Format function, you yourself would need to do all the grunt work that FormatFloat is doing for you through the format string.
So, although I am as opposed to changing third party control's sources as I am opposed to changing the vcl sources, I am with David on this one: find a way to make the third party control use the FormatFloat function. Preferably through a custom descendant or through an interposer class (also known as an interceptor class), but if that fails, by all means change the third party control's source. Just make sure that you mark the changed sections properly so you can easily redo it when switching to a new version of that control.
Far and away the simplest solution will be to take the source of the 3rd party component (you should only consider using 3rd party Delphi components that come with source) and modify it to call FormatFloat rather than Format.

Is it possible to have multiple header rows in a virtual string tree?

I have a need for multiple fixed rows for the header of a virtual string view - something that looks like the effect you get if you set a StringGrid's FixedRows property to a value greater than 1. Is there a way to achieve this?
Some searching on the Soft-Gems website and forums led me to a couple of mentions of an AdvancedHeaderDraw method and a HeaderQueryElements property on the virtual string tree, but I can't work out how to use them.
I also found a demo that uses THeaderControls to achieve a similar effect but there has to be a more elegant solution.
AFAIK there's nothing like this built in. But you could try the VT descendant labeled "Virtual Treeview desc. (nested headers)" on this page.
Note from ten years later: Please note that VT's home is not at Soft gems anymore but at JAM software now but I couldn't find the relevant download there. Also I have no idea if the descendant still works with current VT versions.

Resources