Recent

Author Topic: {Solved] IndexStr() - identifier not found  (Read 4656 times)

HappyLarry

  • Full Member
  • ***
  • Posts: 155
{Solved] IndexStr() - identifier not found
« on: October 08, 2020, 05:37:02 pm »
I have put StrUtils in my uses section and I know this is Ok because I can successfully use wordcount(). However, I get the message 'identifier not found IndexStr' when I use IndexStr (so it's not that I am using it incorrectly)

I've tried using strutils.IndexStr but I get the same message

Anyone else had this problem?
« Last Edit: October 10, 2020, 04:24:39 pm by HappyLarry »
Use Lazarus and Free Pascal and stand on the shoulders of giants . . . very generous giants. Thank you.

dsiders

  • Hero Member
  • *****
  • Posts: 1084
Re: IndexStr() - identifier not found
« Reply #1 on: October 08, 2020, 06:24:10 pm »
I have put StrUtils in my uses section and I know this is Ok because I can successfully use wordcount(). However, I get the message 'identifier not found IndexStr' when I use IndexStr (so it's not that I am using it incorrectly)

I've tried using strutils.IndexStr but I get the same message

Anyone else had this problem?

You haven't told us which version of FPC you're using, or provided any code to help diagnose the problem.

My WAG is that you're not calling it with the correct data types for the arguments, and it can't figure out which of the overloads it needs to use. One uses: String and Array of String. The other: UnicodeString and Array of UnicodeString.

Hope that helps...
Preview Lazarus 3.99 documentation at: https://dsiders.gitlab.io/lazdocsnext

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: IndexStr() - identifier not found
« Reply #2 on: October 08, 2020, 06:41:03 pm »
If you're using Lazarus, what happens when you Ctrl-Click on IndexStr? Where does it takes you or what error (if any) shows?

And which version of Lazarus/FPC?

Finally, what happens if you try this:

Code: Pascal  [Select][+][-]
  1.   ShowMessageFmt('IndexStr says: %d',
  2.                  [IndexStr('string', ['an','array', 'of', 'string' ])]);
  3. {or, for a console program:
  4.   WriteLn('IndexStr says: ',
  5.           IndexStr('string', ['an','array', 'of', 'string' ]));
  6. }
  7.  

(Note: Both should compile and show 'IndexStr says: 3')
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

winni

  • Hero Member
  • *****
  • Posts: 3197
Re: IndexStr() - identifier not found
« Reply #3 on: October 08, 2020, 07:37:29 pm »
Hi!

Line 48 in StrUtils.

Code: Pascal  [Select][+][-]
  1. Function IndexStr(const AText: UnicodeString; const AValues: array of UnicodeString): Integer;  

Robbery in your StrUtils ??

Winni

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: IndexStr() - identifier not found
« Reply #4 on: October 09, 2020, 02:42:10 am »
In FPC 3.2.0 that's line 58, and further down, in line 65:

Code: Pascal  [Select][+][-]
  1. function IndexStr(const AText: string; const AValues: array of string): Integer; inline;

BTW, I always receive a warning about that inline (the usual "will not be inlined") but that is irrelevant in this case ;)

What I don't know is what would happen if one mixed types, say, passing a UnicodeString and an array of AnsiString; which variant would it try first? Hmmm ... that's worth testing ... tomorrow  %)
« Last Edit: October 09, 2020, 02:45:37 am by lucamar »
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

HappyLarry

  • Full Member
  • ***
  • Posts: 155
Re: IndexStr() - identifier not found
« Reply #5 on: October 10, 2020, 11:45:59 am »
@dsiders
I am using Lazarus 1.6  +dfsg-1
FreePascal 3.0.0
Code (strutils is in uses already)
Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button2Click(Sender: TObject);
  2. var
  3.   S:string;
  4.   p:integer;
  5. begin
  6.   S:='abcdefghi';
  7.   p:=IndexStr(S,['f']);
  8.   memo1.lines.add('Position is  '+inttostr(p));
  9. end;
The error is 'identifier not found IndexStr'

@lucamar
PCW 8256 !!! Wow! I had one of those back in '87. (1987 that is). No mouse, no hard disk, Locoscript word pprocessor, no Windows - a PROPER computer.

You code doesn't compile. Error message : 'identifier IndexStr not found'

@winni
For me, there is no IndexStr at line 48 of strutils
Code: Pascal  [Select][+][-]
  1. [code=pascal]unit strutils;
  2.  
  3. interface
  4.  
  5. uses
  6.   SysUtils{, Types};
  7.  
  8. { ---------------------------------------------------------------------
  9.     Case insensitive search/replace
  10.   ---------------------------------------------------------------------}
  11.  
  12. Function AnsiResemblesText(const AText, AOther: string): Boolean;
  13. Function AnsiContainsText(const AText, ASubText: string): Boolean;
  14. Function AnsiStartsText(const ASubText, AText: string): Boolean;
  15. Function AnsiEndsText(const ASubText, AText: string): Boolean;
  16. Function AnsiReplaceText(const AText, AFromText, AToText: string): string;inline;
  17. Function AnsiMatchText(const AText: string; const AValues: array of string): Boolean;inline;
  18. Function AnsiIndexText(const AText: string; const AValues: array of string): Integer;
  19.  
  20. { ---------------------------------------------------------------------
  21.     Case sensitive search/replace
  22.   ---------------------------------------------------------------------}
  23.  
  24. Function AnsiContainsStr(const AText, ASubText: string): Boolean;inline;
  25. Function AnsiStartsStr(const ASubText, AText: string): Boolean;
  26. Function AnsiEndsStr(const ASubText, AText: string): Boolean;
  27. Function AnsiReplaceStr(const AText, AFromText, AToText: string): string;inline;
  28. Function AnsiMatchStr(const AText: string; const AValues: array of string): Boolean;inline;
  29. Function AnsiIndexStr(const AText: string; const AValues: array of string): Integer;
  30.  
  31. { ---------------------------------------------------------------------
  32.     Miscellaneous
  33.   ---------------------------------------------------------------------}
  34.  
  35. Function DupeString(const AText: string; ACount: Integer): string;
  36. Function ReverseString(const AText: string): string;
  37. Function AnsiReverseString(const AText: AnsiString): AnsiString;inline;
  38. Function StuffString(const AText: string; AStart, ALength: Cardinal;  const ASubText: string): string;
  39. Function RandomFrom(const AValues: array of string): string; overload;
  40. Function IfThen(AValue: Boolean; const ATrue: string; const AFalse: string = ''): string; overload;
  41.  
  42. { ---------------------------------------------------------------------
  43.     VB emulations.
  44.   ---------------------------------------------------------------------}
  45.  
  46.  
  47. Line 48 is just above the "Miscellaneous' comment[code=pascal]

This probably explains why the InndexStr is not being found! But why is it missing? I hanen't altered it - I have never looked at strutils until your suggestion. looking through strutils, I can't find IndexStr at all. It looks like someone has stolen it.
« Last Edit: October 10, 2020, 11:48:57 am by HappyLarry »
Use Lazarus and Free Pascal and stand on the shoulders of giants . . . very generous giants. Thank you.

PascalDragon

  • Hero Member
  • *****
  • Posts: 5486
  • Compiler Developer
Re: IndexStr() - identifier not found
« Reply #6 on: October 10, 2020, 11:59:54 am »
Would you please compile with -vu (will generate lots of hidden output in Lazarus that you need to copy using the context menu Copy -> Copy All/Original Messages) and check whether the compiler uses the real StrUtils unit? It could be that there simply is another unit with the same name that the compiler picks up first.

HappyLarry

  • Full Member
  • ***
  • Posts: 155
Re: IndexStr() - identifier not found
« Reply #7 on: October 10, 2020, 12:05:28 pm »
The code below with ANSISTRING (instead of string) works:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button2Click(Sender: TObject);
  2. var
  3.   p:integer;
  4. begin
  5.   ShowMessageFmt('IndexStr says: %d',
  6.                   [AnsiIndexStr('string', ['an','array', 'of', 'string' ])]);
  7.  
  8.   p:=AnsiIndexStr('f',['a','b','c','d','e','f','g','h','i']);
  9.   memo1.lines.add('Position is  '+inttostr(p));
  10. end;

My conclusion is that IndexStr() may be missing from strutils in fp3.0.0.

@PasclDragon
I get Lazarus from the Ubuntu repository, I don't compile it myself. I have only installed it once.
Use Lazarus and Free Pascal and stand on the shoulders of giants . . . very generous giants. Thank you.

PascalDragon

  • Hero Member
  • *****
  • Posts: 5486
  • Compiler Developer
Re: IndexStr() - identifier not found
« Reply #8 on: October 10, 2020, 12:10:33 pm »
I get Lazarus from the Ubuntu repository, I don't compile it myself. I have only installed it once.

That's not what I'm asking. I ask you to compiler your code with that option (see Project Settings -> Compiler Settings -> Debugging) and check the output. This will tell you what units the compiler is looking for and my suspicion is that somewhere in the search paths that the IDE passes along there is a rogue StrUtils (though it's strange in that case that AnsiIndexStr works...).

Can you test a stupidly simple program and compile it on the command line:

Code: Pascal  [Select][+][-]
  1. program test;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. uses
  6.   StrUtils;
  7.  
  8. var
  9.   i: LongInt;
  10. begin
  11.   i := IndexStr('beta', ['alpha', 'beta', 'gamma']);
  12. end.

You should be able to compile it with fpc test.pas. If it does not work, please compile it with fpc -vu test.pas. If it does compile however then it means that something in your project's settings is messed up.

Bart

  • Hero Member
  • *****
  • Posts: 5290
    • Bart en Mariska's Webstek
Re: IndexStr() - identifier not found
« Reply #9 on: October 10, 2020, 12:13:24 pm »
Fpc 3.0.0 indeed dos NOT have IndexStr in StrUtils unit.
See: https://svn.freepascal.org/cgi-bin/viewvc.cgi/tags/release_3_0_0/packages/rtl-objpas/src/inc/strutils.pp?view=markup

It was introduced in fpc 3.0.2.

So, HappyLarry should update his compiler (and/or Lazarus).

Bart

PascalDragon

  • Hero Member
  • *****
  • Posts: 5486
  • Compiler Developer
Re: IndexStr() - identifier not found
« Reply #10 on: October 10, 2020, 12:23:38 pm »
Fpc 3.0.0 indeed dos NOT have IndexStr in StrUtils unit.

Must have missed that HappyLarry still uses 3.0.0... :-[ Thanks for looking that up!

HappyLarry

  • Full Member
  • ***
  • Posts: 155
{Solved] IndexStr() - identifier not found
« Reply #11 on: October 10, 2020, 04:24:08 pm »
So the mystery is solved!
Thanks to dsiders, lucamar, winni, PascalDragon and bart for their help.
Use Lazarus and Free Pascal and stand on the shoulders of giants . . . very generous giants. Thank you.

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: {Solved] IndexStr() - identifier not found
« Reply #12 on: October 10, 2020, 06:06:13 pm »
Well, at least you've got AnsiIndexStr() in 3.0.0, which does exactly the same. Except if you use UnicodeString, of course  8-)
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

 

TinyPortal © 2005-2018