[Solved]Identifier not found "StrToIntDef" even though mode objfpc turn on lazarus / 21-General ---------------------------------------------------------------------- Terno · 2023-09-17 05:21 Hello, i am writing a small convert some C function into Pascal code. It look like this Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i {$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][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i Identifier not found "StrToIntDef"How can I resolve this? ---------------------------------------------------------------------- Fibonacci · 2023-09-17 05:29 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][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i {$mode objfpc}{$typedAddress on} uses SysUtils; function StringToInt(var str: string; var endPtr: PChar): Integer; ---------------------------------------------------------------------- Terno · 2023-09-17 05:33 Now it run! Thank you! ---------------------------------------------------------------------- Fibonacci · 2023-09-17 05:36 BTW. This whole program can be shorten to this Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i 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][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i 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. ---------------------------------------------------------------------- Terno · 2023-09-17 06:17 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. ---------------------------------------------------------------------- cdbc · 2023-09-17 13:42 Hi Maybe this can fulfill your requirements:Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i 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 ~ failureend. HTH Regards Benny