Recent

Author Topic: IsIdentValid to be changed at SysUtils is a problem  (Read 1007 times)

WooBean

  • Sr. Member
  • ****
  • Posts: 277
IsIdentValid to be changed at SysUtils is a problem
« on: July 13, 2024, 09:39:46 am »
Digging around usage '&' in identifiers I felt a need to change definition of the function IsIdentValid from SysUtils (sysstrh.inc, sysstr.inc files).

Trying to compile changed code I have got a message:
sysstr.inc(813,10) Error: Found declaration: IsValidIdent(const AnsiString;Boolean=`FALSE`;Boolean=`FALSE`):Boolean;

Changed code (declarations):

Code: Pascal  [Select][+][-]
  1. //old
  2. function IsValidIdent(const Ident: string; AllowDots: Boolean = False;  StrictDots: Boolean = False): Boolean;
  3. //new
  4. function IsValidIdent(const Ident: string; AllowDots: Boolean = False;
  5.   StrictDots: Boolean = False; AllowAmp: Boolean = False): Boolean;
  6.  

Are there some special rules to touch system level code by ordinary programmers?

Platforms: Win7/64, Linux Mint Ulyssa/64

WooBean

  • Sr. Member
  • ****
  • Posts: 277
Re: IsIdentValid to be changed at SysUtils is a problem
« Reply #1 on: July 13, 2024, 10:22:16 am »
Tried to add compiler '-Us' option ...

Got a message:
fcllaz.pas(10,1) Error: Syntax error, "IMPLEMENTATION" expected but "USES" found

OK, I will put the definition needed elsewhere.
Platforms: Win7/64, Linux Mint Ulyssa/64

jamie

  • Hero Member
  • *****
  • Posts: 6733
Re: IsIdentValid to be changed at SysUtils is a problem
« Reply #2 on: July 13, 2024, 06:25:27 pm »
Why can't you overload it for your local use?

Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, Forms, Controls, Graphics, Dialogs;
  9.  
  10. type
  11.   TForm1 = class(TForm)
  12.   private
  13.  
  14.   public
  15.  
  16.   end;
  17.  function IsValidIdent(const Ident: string; AllowDots: Boolean = False;
  18.   StrictDots: Boolean = False; AllowAmp: Boolean = False): Boolean;  overload;
  19.  
  20. var
  21.   Form1: TForm1;
  22.  
  23. implementation
  24.  
  25. {$R *.lfm}
  26. function IsValidIdent(const Ident: string; AllowDots: Boolean = False;
  27.   StrictDots: Boolean = False; AllowAmp: Boolean = False): Boolean;  overload;
  28. BEgin
  29.  Result:= SysUtils.IsValidIdent(Ident,AllowDots,StrictDots);
  30.  if (Result) and (AllowAmp=False) then
  31.    Result := Pos('&',ident)=0;
  32.  
  33. end;
  34.  
  35. end.
  36.  
  37.  

Something like that ^
The only true wisdom is knowing you know nothing

WooBean

  • Sr. Member
  • ****
  • Posts: 277
Re: IsIdentValid to be changed at SysUtils is a problem
« Reply #3 on: July 13, 2024, 07:16:23 pm »
Why can't you overload it for your local use?
...

I had done something like you sugested (too much simplified, imo).

In {$mode objfpc} there is no need to directly overload a function.

Bad thing is that in summary produced code is doubled (+10%) for one task.

Anyway, +41 lines of code is bearable for Lazarus.
Platforms: Win7/64, Linux Mint Ulyssa/64

MarkMLl

  • Hero Member
  • *****
  • Posts: 8007
Re: IsIdentValid to be changed at SysUtils is a problem
« Reply #4 on: July 13, 2024, 10:49:47 pm »
Are there some special rules to touch system level code by ordinary programmers?

Short answer: yes.

Long answer: you will need to recompile the RTL, and your change will probably break the compiler.

Longer answer: I sympathise, and have been in situations where (as a specific example) I wanted to allow $ inside an identifier since it has traditionally been used as a separator in various assemblers etc.

Extended answer: When you recompile the RTL at a specific version, you will generally also recompile the compiler at that same version... which will then be used to recompile the RTL. Hence if you are changing something fundamental like the definition of an identifier, you risk breaking the compiler's understanding of what is acceptable Pascal.

Hence: don't try modifying System to accommodate application-level code.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

WooBean

  • Sr. Member
  • ****
  • Posts: 277
Re: IsIdentValid to be changed at SysUtils is a problem
« Reply #5 on: July 14, 2024, 08:21:51 am »
Are there some special rules to touch system level code by ordinary programmers?

Short answer: yes.
...
Hence: don't try modifying System to accommodate application-level code.

MarkMLl

I feel myself warned strongly enough. Thanks.
Platforms: Win7/64, Linux Mint Ulyssa/64

 

TinyPortal © 2005-2018