12.2 Creating a library (text and code need some fixes)
Original Reporter info from Mantis: trev @trevoz
-
Reporter name: Trevor Roydhouse
Original Reporter info from Mantis: trev @trevoz
- Reporter name: Trevor Roydhouse
Description:
https://www.freepascal.org/docs-html/current/prog/progse55.html
"Compilation of this source will result in the creation of a library called libsubs.so on unix systems, or subs.dll on Windows or os/2."
The above statement is incorrect. macOS is a certified UNIX and the library name is libsubs.dylib. Perhaps reword as follows:
"Compilation of this source will result in the creation of a library called libsubs.dylib on macOS, libsubs.so on UNIX-like (eg FreeBSD, Linux) systems, or subs.dll on Windows or OS/2."
I believe the library code presented is also incorrect:
begin
if Length >= FromPos then
SubStr := CString + FromPos - 1;
if Length > ToPos then
CString[ToPos] := #0;
end;
should, I believe, be:
begin
if Length >= FromPos then
SubStr := CString + FromPos; <<< remove minus 1
if Length > ToPos + 1 then <<< add plus 1
CString[ToPos + 1] := #0; <<< add plus 1
end;
otherwise with a test string of "1234" the result of SubStr(s, 1, 3) is "12" and not "123" and the result of SubStr(s, 2, 4) is "1234" and not "234".
Steps to reproduce:
Use the example library in a program.