[WFX] Numeric value without thousands separator

Discuss and announce Total Commander plugins, addons and other useful tools here, both their usage and their development.

Moderators: white, Hacker, petermad, Stefan2

Post Reply
User avatar
Dalai
Power Member
Power Member
Posts: 9364
Joined: 2005-01-28, 22:17 UTC
Location: Meiningen (Südthüringen)

[WFX] Numeric value without thousands separator

Post by *Dalai »

Hey guys :),

I'm currently tinkering with some new content fields for my plugins. One of them contains a PID which is a DWORD (32 bit unsigned). Since I figured that ft_numeric_32 (32 bit signed) would potentially be too small, I chose ft_numeric_64 (64 bit signed). The problem is that TC automatically adds thousands separators to the numbers, which is unnecessary and unwanted in this case.

Questions:
  • Is this intentionally done by TC? Yes, I read the WFX help and saw that ft_numeric_64 could be used for example for file sizes.
  • Is there a way to prevent it?
  • Which data type should I choose? ft_numeric_32 which is potentially too small, or ft_numeric_64 which adds the inept thousands separator?
  • BTW: Why is there no unsigned numeric type?
Regards
Dalai
#101164 Personal licence
Ryzen 5 2600, 16 GiB RAM, ASUS Prime X370-A, Win7 x64

Plugins: Services2, Startups, CertificateInfo, SignatureInfo, LineBreakInfo - Download-Mirror
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 48021
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Post by *ghisler(Author) »

Try using ft_numeric_floating instead. It allows to return both a numeric value for searching, and a string value for displaying.

From the plugin writer help:
ft_numeric_floating (New with TC 6.52, plugin interface version >=1.4): You can now put a 0-terminated string immediately behind the 64bit floating point variable, which will then be shown instead in file lists. This is useful if the conversion precision used by TC isn't appropriate for your variables. The numeric variable will still be used for sorting and searching. If the string is empty, TC will ignore it (it is set to 0 before calling this function, so the function will remain backwards-compatible). Example: The numeric value is 0.000002. You can return this value as a 64-bit variable, and the string you find most appropriate, e.g. "2*10^-6" or "0.000002".
Author of Total Commander
https://www.ghisler.com
User avatar
Dalai
Power Member
Power Member
Posts: 9364
Joined: 2005-01-28, 22:17 UTC
Location: Meiningen (Südthüringen)

Post by *Dalai »

Thanks for your answer, and sorry for not responding for such a long time, but I haven't had the time to work on that project :(.

I honestly don't know how ft_numeric_floating is supposed to work :?. To return an integer I used something like

Code: Select all

PInt(FieldValue)^:= Integer(Lsvc.ProcessID);
// or
PInt64(FieldValue)^:= Int64(Lsvc.ProcessID);
To return ft_numeric_floating I tried

Code: Select all

lstrcpyn(PChar(FieldValue), PChar(Format('%u', [Lsvc.ProcessID])), LMaxChars);
but that just shows nonsense. While

Code: Select all

lstrcpyn(PChar(FieldValue), PChar(Format('%8u', [Lsvc.ProcessID])), LMaxChars);
shows the correct value at first glance, it doesn't work well: a) it only works in a Unicode compilation (compiled with Delphi 5 just shows garbage similar to that when not formatting to 8 bytes), and b) TC prefixes some numbers with a space, e.g.

Code: Select all

Application Experience Lookup Service.Gestartet	Automatisch	 800
Application Layer Gateway Service.Gestartet	Manuell	1604
where there's a space in front of the 800 while there's none in front of the 1604. In other words: The column's alignment is set to left but it doesn't look like that because of the leading space.

How to do it the right way? Is there an example somewhere?

Regards
Dalai
#101164 Personal licence
Ryzen 5 2600, 16 GiB RAM, ASUS Prime X370-A, Win7 x64

Plugins: Services2, Startups, CertificateInfo, SignatureInfo, LineBreakInfo - Download-Mirror
User avatar
Dalai
Power Member
Power Member
Posts: 9364
Joined: 2005-01-28, 22:17 UTC
Location: Meiningen (Südthüringen)

Post by *Dalai »

I think I've got it:

Code: Select all

PDouble(FieldValue)^:= Int64(Lsvc.ProcessID);
lstrcpyn(Pointer(NativeUInt(FieldValue)+SizeOf(Double)), PChar(Format('%u', [Lsvc.ProcessID])), LMaxChars - SizeOf(Double));
(I've declared NativeUInt as Cardinal in my Delphi 5.) This works on all platforms, be it old ANSI Delphi, Win32 or Win64. However, I'm absolutely not sure if the data types I used are correct. Pointer arithmetic is not my world, and pointers are one reason for me to use Delphi because most of the time you don't have to deal with them ;).

Regards
Dalai
#101164 Personal licence
Ryzen 5 2600, 16 GiB RAM, ASUS Prime X370-A, Win7 x64

Plugins: Services2, Startups, CertificateInfo, SignatureInfo, LineBreakInfo - Download-Mirror
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 48021
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Post by *ghisler(Author) »

Looks good to me!
Author of Total Commander
https://www.ghisler.com
User avatar
Dalai
Power Member
Power Member
Posts: 9364
Joined: 2005-01-28, 22:17 UTC
Location: Meiningen (Südthüringen)

Post by *Dalai »

That's good to know. Thanks!

Just out of curiosity: What's the reason for showing 32 bit integer values without and 64 bit integers with a thousands separator?

Regards
Dalai
#101164 Personal licence
Ryzen 5 2600, 16 GiB RAM, ASUS Prime X370-A, Win7 x64

Plugins: Services2, Startups, CertificateInfo, SignatureInfo, LineBreakInfo - Download-Mirror
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 48021
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Post by *ghisler(Author) »

64 bit integers are often used for file sizes, which are usually shown with thousands separators.
Author of Total Commander
https://www.ghisler.com
Post Reply