Lazarus
Programming => General => Topic started by: egsuh on April 12, 2025, 11:03:52 am
Title:
[SOLVED] Is this a valid code?
Post by:
egsuh
on
April 12, 2025, 11:03:52 am
In following example, if Options['LoopSelect'] is not 'true' or 'false' then EConvertError will be raised.
I'd like to treat '' as false.
Code: Pascal
[Select]
[+]
[-]
function
TBlockStart
.
getLoopSelect
:
boolean
;
begin
try
Result
:
=
StrToBool
(
Options
[
'LoopSelect'
]
)
;
except
Result
:
=
False
;
end
;
end
;
Title:
Re: Is this a valid code?
Post by:
Paolo
on
April 12, 2025, 12:17:50 pm
Trystrtobool my help here ?
Title:
Re: Is this a valid code?
Post by:
n7800
on
April 12, 2025, 12:23:22 pm
Actually, there is
StrToBoolDef
for this:
Code: Pascal
[Select]
[+]
[-]
function
StrToBoolDef
(
const
S
:
string
;
Default
:
Boolean
)
:
Boolean
;
Title:
Re: Is this a valid code?
Post by:
n7800
on
April 12, 2025, 12:25:46 pm
By the way, there are global arrays
TrueBoolStrs
and
FalseBoolStrs
, in which you can specify acceptable values.
Title:
Re: Is this a valid code?
Post by:
egsuh
on
April 12, 2025, 12:47:45 pm
function StrToBoolDef(const S: string; Default: Boolean): Boolean;
This really helps, and good enough. Thank you very much.
TinyPortal
© 2005-2018