Recent

Author Topic: Error: Identifier not found  (Read 1776 times)

Brian75

  • Newbie
  • Posts: 2
Error: Identifier not found
« on: June 20, 2023, 11:55:56 am »
Hi I hope someone can help me with what is probably a quite simple problem. I have a unit called DK that has been working flawlessly for many years. It was developped by a colleague of mine who is no longer with us. I have been able up to now to just use the unit when compiling programs using said unit without encounting any problems. I am not sure why it suddenly is not working.

The first error code I get is this: DK.pas(33.8) Error: Identifier not found "inchr"

I might add that I have just had my PC replaced and thus I have had a new version of Lazarus installed (version 2.2.6) I am not sure what version I had on my old PC, but I had it installed sometime around 2015 so it must have been quite dated. Could the problem be related to the newer version of Lazarus or maybe something in the settings menu I should tweak? BTW i have the option -Sd turned on.

Any help would be greatly appreciated.

Please find the code below.

Code: Pascal  [Select][+][-]
  1. unit dk;
  2. {  Behandling af tekst i dansk tegnsæt.  }
  3.  
  4. interface
  5.  
  6. procedure DKupperch(var inchr:char);
  7.  
  8. function DKuppercs(var instr:string):string;
  9.  
  10. procedure DKuppercv(var instr:string);
  11.  
  12. procedure DKupperc1(var instr:string);
  13.  
  14.  
  15. procedure DKansich(var inchr:char);
  16.  
  17. function DKansics(var instr:string):string;
  18.  
  19. procedure DKansicv(var instr:string);
  20.  
  21.  
  22. procedure DKasciich(var inchr:char);
  23.  
  24. function DKasciics(var instr:string):string;
  25.  
  26. procedure DKasciicv(var instr:string);
  27.  
  28.  
  29. implementation
  30.  
  31. procedure DKupperch;
  32. begin
  33.   case inchr of
  34.      '‘':       inchr:='’';
  35.      '›':       inchr:='';
  36.      '†':       inchr:='';
  37.      '„':       inchr:='Ž';
  38.      '‚':       inchr:='';
  39.      'Š':       inchr:='Ô';
  40.      '”':       inchr:='™';
  41.      '':       inchr:='š';
  42.  
  43.      'æ':       inchr:='Æ';
  44.      'ø':       inchr:='Ø';
  45.      'å':       inchr:='Å';
  46.      'é':       inchr:='É';
  47.      'è':       inchr:='È';
  48.      'ä':       inchr:='Ä';
  49.      'ö':       inchr:='Ö';
  50.      'ü':       inchr:='Ü';
  51.   else
  52.      inchr:=upcase(inchr)
  53.   end;
  54. end;
  55.  
  56. function DKuppercs;
  57. var
  58.   udstr:string;
  59.   i:integer;
  60. begin
  61.   udstr:=instr;
  62.   for i:=1 to length(udstr) do dkupperch(udstr[i]);
  63.   DKuppercs:=udstr;
  64. end;
  65.  
  66. procedure DKuppercv;
  67. var
  68.   i:integer;
  69. begin
  70.   for i:=1 to length(instr) do dkupperch(instr[i]);
  71. end;
  72.  
  73. procedure DKupperc1;
  74. begin
  75.   dkupperch(instr[1]);
  76. end;
  77.  
  78. procedure DKansich;
  79. begin
  80.   case inchr of
  81.      '‘':       inchr:='æ';
  82.      '›':       inchr:='ø';
  83.      '†':       inchr:='å';
  84.      '„':       inchr:='é';
  85.      '‚':       inchr:='è';
  86.      'Š':       inchr:='ä';
  87.      '”':       inchr:='ö';
  88.      '':       inchr:='ü';
  89.  
  90.      '’':       inchr:='Æ';
  91.      '':       inchr:='Ø';
  92.      '':       inchr:='Å';
  93.      'Ž':       inchr:='É';
  94.      '':       inchr:='È';
  95.      'Ô':       inchr:='Ä';
  96.      '™':       inchr:='Ö';
  97.      'š':       inchr:='Ü';
  98.   end;
  99. end;
  100.  
  101. function DKansics;
  102. var
  103.   udstr:string;
  104.   i:integer;
  105. begin
  106.   udstr:=instr;
  107.   for i:=1 to length(udstr) do DKansich(udstr[i]);
  108.   DKansics:=udstr;
  109. end;
  110.  
  111. procedure DKansicv;
  112. var
  113.   i:integer;
  114. begin
  115.   for i:=1 to length(instr) do DKansich(instr[i]);
  116. end;
  117.  
  118. procedure DKasciich;
  119. begin
  120.   case inchr of
  121.      'æ':       inchr:='‘';
  122.      'ø':       inchr:='›';
  123.      'å':       inchr:='†';
  124.      'é':       inchr:='„';
  125.      'è':       inchr:='‚';
  126.      'ä':       inchr:='Š';
  127.      'ö':       inchr:='”';
  128.      'ü':       inchr:='';
  129.  
  130.      'Æ':       inchr:='’';
  131.      'Ø':       inchr:='';
  132.      'Å':       inchr:='';
  133.      'É':       inchr:='Ž';
  134.      'È':       inchr:='';
  135.      'Ä':       inchr:='Ô';
  136.      'Ö':       inchr:='™';
  137.      'Ü':       inchr:='š';
  138.   end;
  139. end;
  140.  
  141. function DKasciics;
  142. var
  143.   udstr:string;
  144.   i:integer;
  145. begin
  146.   udstr:=instr;
  147.   for i:=1 to length(udstr) do DKasciich(udstr[i]);
  148.   DKasciics:=udstr;
  149. end;
  150.  
  151. procedure DKasciicv;
  152. var
  153.   i:integer;
  154. begin
  155.   for i:=1 to length(instr) do DKasciich(instr[i]);
  156. end;
  157.  
  158. end.                    

TRon

  • Hero Member
  • *****
  • Posts: 3618
Re: Error: Identifier not found
« Reply #1 on: June 20, 2023, 12:02:46 pm »
The proto headers (the part in the interface section) do not match the header used in the implementation section. Actually it is the other way around in that the function headers in the implementation section do not match that of the function headers declared in the interface section.

I have no idea if Free Pascal has a switch/option for that but in case not, then make sure the function headers match. That is where the missing identifier seem to originate from.
« Last Edit: June 20, 2023, 12:05:34 pm by TRon »
This tagline is powered by AI

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11930
  • FPC developer.
Re: Error: Identifier not found
« Reply #2 on: June 20, 2023, 12:46:10 pm »
The FPC-own modes (fpc and objfpc) are more strict. Try to enable delphi or TP mode, whatever it was written for

(  {$mode delphi}  or {$mode tp}  just under the interface line)

TRon

  • Hero Member
  • *****
  • Posts: 3618
Re: Error: Identifier not found
« Reply #3 on: June 20, 2023, 12:52:11 pm »
I was experimenting with the modes but initially was unable to match any that compilers it. I finally managed to find it: it is mode delphiunicode. The characters and strings used in the comparison seem to be unicode.
This tagline is powered by AI

Brian75

  • Newbie
  • Posts: 2
Re: Error: Identifier not found
« Reply #4 on: June 20, 2023, 01:10:48 pm »
Thank you TRon and marcov.

Sorry for inconveniencing you. After your insightful comments I have realized that when setting the option -Sd (Same as -Mdelphi) I did not check the box Set compiler options as default. I guess that meant it was only switched on for the active session.

Thank you again for helping me sort this out. Very much appreciated.

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11930
  • FPC developer.
Re: Error: Identifier not found
« Reply #5 on: June 20, 2023, 01:54:10 pm »
An dos/win9x era Ascii probably also works but you need to have the relevant codepage default that maps all these signs to single byte characters. Probably also need to take care of the encoding of the sourcefile with some $codepage statement.

But those are inherit assumptions of the code.


Nicole

  • Hero Member
  • *****
  • Posts: 1009
Re: Error: Identifier not found
« Reply #6 on: June 20, 2023, 07:18:54 pm »
What will happen, if you make it a class and declare a Var?

  TMyClass = class(TObject) 
procedure DKupperch(var inchr:char);
...
end;

Var MyClass: TMyClass;

implementation
TMyClass.DKupperch(var inchr:char);
begin
..
end;

call:
MyClass.DKupperch(  value   );

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11930
  • FPC developer.
Re: Error: Identifier not found
« Reply #7 on: June 20, 2023, 07:46:55 pm »
Shouldn't matter, this is about base types and directives that set runtime and source encoding

Nicole

  • Hero Member
  • *****
  • Posts: 1009
Re: Error: Identifier not found
« Reply #8 on: June 21, 2023, 10:35:37 am »
I saw this error message several times within the past years. I my case I solved it by
Code: Pascal  [Select][+][-]
  1. Var MyClass: TMyClass;

In other words: I forgot to declare the Var for a class some times in my programming life.

Or to include the unit.

TRon

  • Hero Member
  • *****
  • Posts: 3618
Re: Error: Identifier not found
« Reply #9 on: June 21, 2023, 10:55:06 am »
In other words: I forgot to declare the Var for a class some times in my programming life.
That is probably what happens in most situations like the example you showed.

However, in this case you can see that the variables are declared in the function headers it is just that the compiler is unable to 'see' them.

That has to do with the fact that the function header as declared in the interface section of the unit does not match the function header as declared in the implementation section of the unit.

for example:
Code: Pascal  [Select][+][-]
  1. interface
  2. procedure DKupperch(var inchr:char);
  3.  

Code: Pascal  [Select][+][-]
  1. implementation
  2. procedure DKupperch;
  3.  

Do you note the difference in the function header ?

So, in theory that would give a possibility to say: "You are doing it wrong" and the compiler is in its right to complain about it.

Except for one minor detail and that is that some Pascal dialects actually allow you to omit the parameter declaration of a function header in the implementation section of a unit. In such cases these are 'automatically' used from the interfaced declaration of the function so that the compiler is able to make sense out of it.

It is actually a very handy feature as it saves a lot of typing. The bad thing about it is that if your have many of such declarations and forgot about the parameter list of a particular function then you would have to scroll up in your source-code to see the declaration and determine the parameter names and types (manually).

Note that such things were invented when there didn't exist all those fancy code-editors that exists today.

The second issue is an entire other one and has to do with the fact that the code as presented uses uni-code characters and that has to do with how the strings and character declarations are being treated. But that is out of scope of what I reacted to.
This tagline is powered by AI

 

TinyPortal © 2005-2018