Forum > General

UTF8 and numeric to string conversion

(1/4) > >>

hy:
Hi I am having a program that handles widestrings most of the time correctly (lots of namens with diacritical characters handled correctly). But there are two places in the code where I need to display the value of an Angle in Degrees '°'.
I tried several conversions to no avail. The general Idea is:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---var      fAngle : double;      sAngle,      sCenterLabel   : string;begin     fAngle := calculateAngle;     sAngle := FloatToStr(fAngle) ;      sCenterLabel := sAngle +'°'end;Actually the '°' is always replaced by a questionmark
Any help apreciated
Note:
if I do the following assignment:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} --- sCenterLabel := '23,3'+'°'; It works so I think the result of floatToStr is a short and the rest is trated as shortstring as well.

wp:

--- Quote from: hy on January 14, 2018, 05:30:26 pm ---... handles widestrings ...
... is trated as shortstring as well...

--- End quote ---
What are you doing? Why "widestring", why "shortstring"? Simply use string, and everything works fine.

There's really no need to work with widestrings unless you call such functions in a dll or make system calls on Windows (but you are on Linux anyway). And shortstring is technology of the last century.

hy:

--- Quote from: wp on January 14, 2018, 05:44:49 pm ---What are you doing? Why "widestring", why "shortstring"? Simply use string, and everything works fine.

--- End quote ---
I do not have any widestrings or shortstrings in my code.
But the result of floatToStr is obviously not able to accept other than ansi.

wp:

--- Quote from: hy on January 14, 2018, 05:47:28 pm ---But the result of floatToStr is obviously not able to accept other than ansi.

--- End quote ---

No, try attached demo. The bug must be somewhere else.

I see in your signature that you use fpc 2.6.4 which still has the old string routines. Upgrade to 3.0.4, maybe this resolves your issue magically.

hy:
The tag line is not updated i am on fpc 3.0.4

i also get

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---ym_main.pas(5682,39) Warning: Implicit string type conversion with potential data loss from "WideString" to "AnsiString"The message above is the assignment of FloatToStr()...


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---ym_main.pas(5681,26) Warning: Implicit string type conversion from "AnsiString" to "WideString" The message above is the assignment of sCenterLabel := sAngle + '°';

Navigation

[0] Message Index

[#] Next page

Go to full version