Hi!
According to docs, the Str procedure is declared like this:
procedure Str(var X: TNumericType[:NumPlaces[:Decimals]];var S: String)
Can I declare a procedure like this? If so, how can I use inside the procedure the :NumPlaces and :Decimals values?
Thak you.
You can however, emulate this behavior with an overloaded procedure, i.e.: *you* write an overloaded proc, for *every* possible type you'd come across!
Then leave it up to the compiler to pick the right one at runtime :D
You can however, emulate this behavior with an overloaded procedure, i.e.: *you* write an overloaded proc, for *every* possible type you'd come across!That method works reasonably well when parameters are required but when values are optional and worse, separated by semicolons, overloading doesn't "map" that functionality very well.
Then leave it up to the compiler to pick the right one at runtime :D
print(to: stdout value: fred);
print(to: stdout value: fred format: something);
print(to: stdout format: something value: fred);
print(to-value: fred);
You can however, emulate this behavior with an overloaded procedure, i.e.: *you* write an overloaded proc, for *every* possible type you'd come across!
Then leave it up to the compiler to pick the right one at runtime :D
But that still wouldn't handle : as the parameter separator.
str is a reserved word and a compiler intrinsic. just read all other answers.
str belongs to the early pascal family, it is not related to any dialect.
str belongs to the early pascal family, it is not related to any dialect.I could not find it in Wirth’s 1973 Revised Report (https://DOI.org/10.3929/ethz-a-000814158). Maybe you have some magical capabilities of reading between the lines. GPC claims it was a UCSD Pascal extension in origin that was generalized by BP (https://www.GNU-Pascal.de/gpc/Str.html#:~:text=Str%20is,extension.). This info is what I incorporated into the wiki (https://wiki.FreePascal.org/Special:Diff/155697).
I could not find it in Wirth’s 1973 Revised Report (https://DOI.org/10.3929/ethz-a-000814158). Maybe you have some magical capabilities of reading between the lines. GPC claims it was a UCSD Pascal extension in origin that was generalized by BP (https://www.GNU-Pascal.de/gpc/Str.html#:~:text=Str%20is,extension.). This info is what I incorporated into the wiki (https://wiki.FreePascal.org/Special:Diff/155697).
str is a reserved word and a compiler intrinsic.First false, second true.
It possible to declare a procedure or function named Str, but cannot use a colon as a parameter separator.
[…] The reference manual should somewhere document Write(), WriteLn(), Str() and WriteStr() as special cases: possibly not reserved words but definitely not as ordinary procedures amenable to redefinition. […]In FPC you can always access the built‑in procedures by specifying an FQI, say system.writeLn despite a custom writeLn declared in the current scope.
[…] The reference manual should somewhere document Write(), WriteLn(), Str() and WriteStr() as special cases: possibly not reserved words but definitely not as ordinary procedures amenable to redefinition. […]In FPC you can always access the built‑in procedures by specifying an FQI, say system.writeLn despite a custom writeLn declared in the current scope.
Both chr() and str(). The two belong together.
It is rather fultile to argue otherwise.
The reference manual should somewhere document Write(), WriteLn(), Str() and WriteStr() as special cases: possibly not reserved words but definitely not as ordinary procedures amenable to redefinition.
Hi!
According to docs, the Str procedure is declared like this:Can I declare a procedure like this? If so, how can I use inside the procedure the :NumPlaces and :Decimals values?
procedure Str(var X: TNumericType[:NumPlaces[:Decimals]];var S: String)
Thak you.
Procedure myStr(x:Integer;Numplaces:word;Decimals:word Var destVar:string);overload;
Procedure myStr(x:Integer;Numplaces:word; Var destVar:string);overload;
Procedure myStr(x:Integer;Var destVar:string);overload;
Hint1=Where you use one type X:integer; I think overload work very good, Procedure myStr(Var destvar:string;x:Integer;Numplaces,Decimals:word;);overload;
Procedure myStr(Var destvar:string;x:Integer;Numplaces:word);overload;
Procedure myStr(Var destvar:string;x:Integer);overload;
Hint3=I do not have experince with overload; inside Delphi & Pascal.Hint1=Where you use one type X:integer; I think overload work very good,In that case you can just as well use Mark's suggestion and use format, e.g.
Hint2=You change definition of myStr like these bellow; moving all fix types at begin of (..
Question= The TNumericType exists inside LazarusForumPascal?Not for the end-user.
The reference manual should somewhere document Write(), WriteLn(), Str() and WriteStr() as special cases: possibly not reserved words but definitely not as ordinary procedures amenable to redefinition.
Those are just ordinary identifiers that can be redefined as one wants. Same with e.g. Break and Exit. That they have some magic ability is no problem, because one can just use System.XXX to still access them if necessary.