Lazarus
Home
Help
TinyPortal
Search
Login
Register
Lazarus
»
Forum
»
Programming
»
General
»
[Solved]Identifier not found "StrToIntDef" even though mode objfpc turn on
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
Recent
TPrintDialog disable Prop...
by
Weitentaaal
[
Today
at 03:11:44 pm]
IDE tabs and spaces, auto...
by
chris_laz
[
Today
at 02:49:53 pm]
Cannot update a record us...
by
Zvoni
[
Today
at 02:39:34 pm]
[maybe SOLVED] BUG in Inp...
by
robert rozee
[
Today
at 02:38:54 pm]
Lazarus Release Candidate...
by
Martin_fr
[
Today
at 01:16:07 pm]
Move tab to other pagecon...
by
majid.ebru
[
Today
at 01:15:57 pm]
How to get and use the ma...
by
Hansaplast
[
Today
at 12:46:42 pm]
Tcsvdataset issue
by
Zvoni
[
Today
at 12:17:21 pm]
[Solved] DBEXPORT TFixedl...
by
Zvoni
[
Today
at 10:15:53 am]
NIL vs. Assign: when to u...
by
MarkMLl
[
Today
at 09:47:37 am]
Converting a Project from...
by
Zvoni
[
Today
at 08:11:37 am]
Uninstall
by
TRon
[
Today
at 03:56:15 am]
Using Bresenham's line al...
by
TBMan
[
Today
at 02:40:18 am]
[SOLVED] Remote access to...
by
wcage03
[
Today
at 02:12:39 am]
Hooking to `OnISupport` d...
by
Gustavo 'Gus' Carreno
[
Today
at 02:12:35 am]
Remote access to database...
by
wcage03
[
Today
at 12:48:40 am]
Program crashing with exc...
by
jamie
[March 19, 2025, 11:20:14 pm]
Checking for number or no...
by
Bart
[March 19, 2025, 10:05:18 pm]
Form goes Frame - drag an...
by
Nicole
[March 19, 2025, 07:08:08 pm]
How to block mouse withou...
by
Yurgenz
[March 19, 2025, 06:45:54 pm]
How to download/compile l...
by
zeljko
[March 19, 2025, 06:13:35 pm]
LazTTF2Vector - An Enhanc...
by
maurog
[March 19, 2025, 06:07:44 pm]
AVRPascal – free code edi...
by
ackarwow
[March 19, 2025, 05:22:53 pm]
Freepascal Toolkit in VS ...
by
PhoenixHawk
[March 19, 2025, 04:04:16 pm]
Can't put Lazarus in dock
by
JimKueneman
[March 19, 2025, 03:21:23 pm]
« previous
next »
Print
Pages: [
1
]
Author
Topic: [Solved]Identifier not found "StrToIntDef" even though mode objfpc turn on (Read 751 times)
Terno
Newbie
Posts: 3
[Solved]Identifier not found "StrToIntDef" even though mode objfpc turn on
«
on:
September 17, 2023, 07:21:35 am »
Hello, i am writing a small convert some C function into Pascal code.
It look like this
Code: Pascal
[Select]
[+]
[-]
{$mode objfpc}
{$typedAddress on}
function
StringToInt
(
var
str
:
string
;
var
endPtr
:
PChar
)
:
Integer
;
var
tempStr
:
string
;
i
:
Integer
;
begin
// Trim leading whitespace
while
(
str <>
''
)
and
(
str
[
1
]
<
=
' '
)
do
Delete
(
str
,
1
,
1
)
;
// Find the end of the string
endPtr
:
=
Addr
(
str
)
;
while
endPtr
^
<>
#0
do
Inc
(
endPtr
)
;
// Convert the string to integer
tempStr
:
=
Copy
(
str
,
1
,
endPtr
-
Addr
(
str
)
)
;
// Get substring until endPtr
Val
(
tempStr
,
Result
,
i
)
;
// Update endPtr to point to the actual end of the substring
Dec
(
endPtr
)
;
// Trim trailing whitespace
while
(
tempStr <>
''
)
and
(
tempStr
[
Length
(
tempStr
)
]
<
=
' '
)
do
Delete
(
tempStr
,
Length
(
tempStr
)
,
1
)
;
// Return the integer value
Result
:
=
StrToIntDef
(
tempStr
,
0
)
;
end
;
var
str
:
string
;
endPtr
:
PChar
;
intValue
:
Integer
;
begin
str
:
=
'12345 '
;
intValue
:
=
StringToInt
(
str
,
endPtr
)
;
// Access the end position using endPtr
Writeln
(
'End position pointer: '
,
Ord
(
endPtr
^
)
)
;
// Print the converted integer value
Writeln
(
'Integer value: '
,
intValue
)
;
end
.
But the compiler alway throw error
Code: Pascal
[Select]
[+]
[-]
Identifier
not
found "StrToIntDef"
How can I resolve this?
«
Last Edit: September 17, 2023, 09:12:23 am by Terno
»
Logged
Fibonacci
Hero Member
Posts: 653
Internal Error Hunter
Re: Identifier not found "StrToIntDef" even though I have turn on mode objfpc
«
Reply #1 on:
September 17, 2023, 07:29:22 am »
Its function from SysUtils so you need to add it to the uses
https://www.freepascal.org/docs-html/rtl/sysutils/strtointdef.html
Code: Pascal
[Select]
[+]
[-]
{$mode objfpc}
{$typedAddress on}
uses
SysUtils
;
function
StringToInt
(
var
str
:
string
;
var
endPtr
:
PChar
)
:
Integer
;
Logged
Terno
Newbie
Posts: 3
Re: Identifier not found "StrToIntDef" even though I have turn on mode objfpc
«
Reply #2 on:
September 17, 2023, 07:33:36 am »
Now it run! Thank you!
«
Last Edit: September 17, 2023, 08:59:11 am by Terno
»
Logged
Fibonacci
Hero Member
Posts: 653
Internal Error Hunter
Re: Identifier not found "StrToIntDef" even though I have turn on mode objfpc
«
Reply #3 on:
September 17, 2023, 07:36:28 am »
BTW. This whole program can be shorten to this
Code: Pascal
[Select]
[+]
[-]
uses
SysUtils
;
var
str
:
string
;
int
:
integer
;
begin
str
:
=
'12345 '
;
int
:
=
StrToIntDef
(
str
.
Trim
,
0
)
;
writeln
(
'str to int = '
,
int
)
;
end
.
Or
Code: Pascal
[Select]
[+]
[-]
uses
SysUtils
;
var
str
:
string
;
int
:
integer
;
begin
str
:
=
'12345 '
;
if
TryStrToInt
(
str
.
Trim
,
int
)
then
writeln
(
'int = '
,
int
)
else
writeln
(
'cant do it'
)
;
end
.
Logged
Terno
Newbie
Posts: 3
Re: Identifier not found "StrToIntDef" even though I have turn on mode objfpc
«
Reply #4 on:
September 17, 2023, 08:17:57 am »
But I want the function have a pointer to point to the end of the string like strtol in C/C++.
It is a bit pain staking to do this.
Logged
cdbc
Hero Member
Posts: 1964
Re: [Solved]Identifier not found "StrToIntDef" even though mode objfpc turn on
«
Reply #5 on:
September 17, 2023, 03:42:59 pm »
Hi
Maybe this can fulfill your requirements:
Code: Pascal
[Select]
[+]
[-]
uses
SysUtils
;
var
str
:
string
;
int
:
integer
;
EndPtr
:
pchar
;
begin
str
:
=
'12345 '
;
if
TryStrToInt
(
str
.
Trim
,
int
)
then
begin
EndPtr
:
=
pchar
(
str
[
length
(
str
)
]
)
;
writeln
(
'int = '
,
int
)
end
else
begin
EndPtr
:
=
nil
;
writeln
(
'cant do it'
)
;
end
;
// else ~ failure
end
.
HTH
Regards Benny
Logged
If it ain't broke, don't fix it
PCLinuxOS(rolling release) 64bit -> KDE5 -> FPC 3.2.2 -> Lazarus 3.6 up until Jan 2024 from then on it's both above &: KDE5/QT5 -> FPC 3.3.1 -> Lazarus 4.99
Print
Pages: [
1
]
« previous
next »
Lazarus
»
Forum
»
Programming
»
General
»
[Solved]Identifier not found "StrToIntDef" even though mode objfpc turn on
TinyPortal
© 2005-2018