Lazarus
Home
Help
TinyPortal
Search
Login
Register
Lazarus
»
Forum
»
Programming
»
General
»
IntToStr bring me to lost hairs
Free Pascal
Website
Downloads
Wiki
Documentation
Bugtracker
Mailing List
Lazarus
Website
Downloads (Laz+FPC)
Packages (OPM)
FAQ
Wiki
Documentation (RTL/FCL/LCL)
Bugtracker
CCR Bugs
GIT
Mailing List
Other languages
Foundation
Website
Useful Wiki Links
Project Roadmap
Getting the Source
Screenshots
How to use the forum
About donations (wiki)
Bookstore
Computer Math and Games in Pascal
(preview)
Lazarus Handbook
Search
Advanced search
WIKI Timeout issues
Please read here if you have trouble connecting to the wiki
Recent
TTask 'file not found' er...
by
Thaddy
[
Today
at 07:09:45 am]
Variable number of button...
by
Thaddy
[
Today
at 06:59:55 am]
Has the function of findi...
by
gary
[
Today
at 06:02:48 am]
TaurusTLS 1.0.0.25 beta 2...
by
J. Peter Mugaas
[
Today
at 05:26:43 am]
My second "paint" program
by
TBMan
[
Today
at 04:13:41 am]
Zeos 8, Acces violation
by
incendio
[
Today
at 04:08:35 am]
Status and Maintenance of...
by
dbannon
[
Today
at 02:41:47 am]
Opencv version 4.6 C++ AP...
by
Mongkey
[
Today
at 02:39:07 am]
Are there units that give...
by
jamie
[
Today
at 02:36:49 am]
TBitBtn no longer shows g...
by
wp
[
Today
at 01:09:04 am]
Modbus summary thread
by
bobby100
[June 22, 2025, 11:18:35 pm]
connection lost
by
ADMGNS
[June 22, 2025, 10:58:19 pm]
Loop Iteration Speed Test
by
Martin_fr
[June 22, 2025, 10:51:08 pm]
Shenanigans with ncurses ...
by
Gustavo 'Gus' Carreno
[June 22, 2025, 10:28:13 pm]
How to export Pascal vari...
by
ecm
[June 22, 2025, 09:54:37 pm]
What WinAPI functions can...
by
440bx
[June 22, 2025, 09:01:50 pm]
Error: Identifier not fou...
by
Yoghoo
[June 22, 2025, 06:34:44 pm]
Lazarus Release 4.0
by
JuhaManninen
[June 22, 2025, 05:20:55 pm]
[SOLVED] RecordCount not ...
by
1HuntnMan
[June 22, 2025, 05:10:04 pm]
How to fix "Warning: Enco...
by
ecm
[June 22, 2025, 05:09:33 pm]
Classes vs Objects
by
TBMan
[June 22, 2025, 04:34:59 pm]
WinInet compiling errors.
by
440bx
[June 22, 2025, 03:50:03 pm]
Replace controls dynamica...
by
Aruna
[June 22, 2025, 03:40:02 pm]
Hints for method name mis...
by
dbannon
[June 22, 2025, 12:50:07 pm]
[Solved] save dbgrid colu...
by
Hansvb
[June 22, 2025, 11:28:50 am]
« previous
next »
Print
Pages: [
1
]
Author
Topic: IntToStr bring me to lost hairs (Read 720 times)
paule32
Hero Member
Posts: 516
One in all. But, not all in one.
IntToStr bring me to lost hairs
«
on:
May 23, 2025, 04:41:25 pm »
I have this Function:
Code: Pascal
[Select]
[+]
[-]
function
IntToStr32
(
AValue
:
Integer
)
:
PChar
;
stdcall
;
export
;
var
temp
:
PChar
;
begin
temp
:
=
StrAlloc
(
64
)
;
_itoa
(
AValue
,
temp
,
10
)
;
if
AValue
=
123
then
writeln
(
'temp: '
+
temp
)
;
Exit
(
temp
)
;
end
;
when I call it with IntToStr32(123) I get no writeln
the Function _itioa is:
Code: Pascal
[Select]
[+]
[-]
function
_itoa
(
Value
:
Integer
;
Buffer
:
PChar
;
Radix
:
Integer
)
:
PChar
;
cdecl
;
external
'msvcrt.dll'
name
'_itoa'
;
But the following Code works:
Code: Pascal
[Select]
[+]
[-]
function
IntToStr32
(
AValue
:
Integer
)
:
PChar
;
stdcall
;
export
;
var
temp
:
PChar
;
begin
AValue
:
=
123
;
temp
:
=
StrAlloc
(
64
)
;
_itoa
(
AValue
,
temp
,
10
)
;
if
AValue
=
123
then
writeln
(
'temp: '
+
temp
)
;
Exit
(
temp
)
;
end
;
Logged
MS-IIS - Internet Information Server, Apache, PHP/HTML/CSS, MinGW-32/64 MSys2 GNU C/C++ 13 (-stdc++20), FPC 3.2.2
A Friend in need, is a Friend indeed.
marcov
Administrator
Hero Member
Posts: 12268
FPC developer.
Re: IntToStr bring me to lost hairs
«
Reply #1 on:
May 23, 2025, 04:45:19 pm »
_itoa has a return value. This is so you know how many characters you have written so that you can provide proper zero terminating.
Logged
paule32
Hero Member
Posts: 516
One in all. But, not all in one.
Re: IntToStr bring me to lost hairs
«
Reply #2 on:
May 23, 2025, 04:50:57 pm »
when I do:
temp := _itoa(AValue, temp, 10);
or:
StrCopy(temp, _itoa(AValue, temp, 10));
I get same results:
temp: 20971088
But not 123.
Logged
MS-IIS - Internet Information Server, Apache, PHP/HTML/CSS, MinGW-32/64 MSys2 GNU C/C++ 13 (-stdc++20), FPC 3.2.2
A Friend in need, is a Friend indeed.
Thaddy
Hero Member
Posts: 17190
Ceterum censeo Trump esse delendam
Re: IntToStr bring me to lost hairs
«
Reply #3 on:
May 23, 2025, 05:00:39 pm »
If you see a
pointer
value why do you stop thinking about what the pointer points to?
Also,
Why do you use C libraries for that?
The Pascal compiler handles that just as efficient.
If I wasn't already certified mad, you will make me even more mad with such questions where you do not do your own research.
Funny you focus on 32 Intel Windows, which is not obtainable from MS anymore.
«
Last Edit: May 23, 2025, 05:13:53 pm by Thaddy
»
Logged
Due to censorship, I changed this to "Nelly the Elephant". Keeps the message clear.
paule32
Hero Member
Posts: 516
One in all. But, not all in one.
Re: IntToStr bring me to lost hairs
«
Reply #4 on:
May 23, 2025, 05:13:14 pm »
good news:
I have found a Solution:
Code: Pascal
[Select]
[+]
[-]
function
IntToStr32
(
Value
:
Integer
)
:
string
;
stdcall
;
export
;
var
Buffer
:
array
[
0
..
31
]
of
Char
;
Temp
:
PChar
;
Negative
:
Boolean
;
Digit
:
Integer
;
Len
:
Integer
;
begin
Len
:
=
0
;
Temp
:
=
@
Buffer
[
0
]
;
Buffer
[
0
]
:
=
#0
;
Negative
:
=
Value <
0
;
if
Negative
then
Value
:
=
-
Value
;
repeat
Digit
:
=
Value
mod
10
;
Move
(
Buffer
[
0
]
,
Buffer
[
1
]
,
Len
+
1
)
;
Buffer
[
0
]
:
=
Chr
(
Ord
(
'0'
)
+
Digit
)
;
Inc
(
Len
)
;
Value
:
=
Value
div
10
;
until
Value
=
0
;
if
Negative
then
begin
Move
(
Buffer
[
0
]
,
Buffer
[
1
]
,
Len
+
1
)
;
Buffer
[
0
]
:
=
'-'
;
Inc
(
Len
)
;
end
;
SetString
(
Result
,
Buffer
,
Len
)
;
end
;
Logged
MS-IIS - Internet Information Server, Apache, PHP/HTML/CSS, MinGW-32/64 MSys2 GNU C/C++ 13 (-stdc++20), FPC 3.2.2
A Friend in need, is a Friend indeed.
Thaddy
Hero Member
Posts: 17190
Ceterum censeo Trump esse delendam
Re: IntToStr bring me to lost hairs
«
Reply #5 on:
May 23, 2025, 05:15:02 pm »
Yup, the setstring trick. (it is not a trick!)
One day you will learn.
Your code is still highly inefficient, though: you should use val(), which is also used by inttostr.
Then again: we discussed that.... and you did not understand that.
This part is exceptionally bad, what are you trying there?
Code: Pascal
[Select]
[+]
[-]
repeat
Digit
:
=
Value
mod
10
;
Move
(
Buffer
[
0
]
,
Buffer
[
1
]
,
Len
+
1
)
;
Buffer
[
0
]
:
=
Chr
(
Ord
(
'0'
)
+
Digit
)
;
Inc
(
Len
)
;
Value
:
=
Value
div
10
;
until
Value
=
0
;
Makes no sense.
«
Last Edit: May 23, 2025, 05:28:40 pm by Thaddy
»
Logged
Due to censorship, I changed this to "Nelly the Elephant". Keeps the message clear.
paule32
Hero Member
Posts: 516
One in all. But, not all in one.
Re: IntToStr bring me to lost hairs
«
Reply #6 on:
May 23, 2025, 06:48:49 pm »
it is not the efficency that I looking for.
I looking for workable...
Logged
MS-IIS - Internet Information Server, Apache, PHP/HTML/CSS, MinGW-32/64 MSys2 GNU C/C++ 13 (-stdc++20), FPC 3.2.2
A Friend in need, is a Friend indeed.
Print
Pages: [
1
]
« previous
next »
Lazarus
»
Forum
»
Programming
»
General
»
IntToStr bring me to lost hairs
TinyPortal
© 2005-2018