Recent

Author Topic: Need help with THashedStringList  (Read 357 times)

nikel

  • Jr. Member
  • **
  • Posts: 99
Need help with THashedStringList
« on: April 18, 2019, 02:24:09 pm »
Hi, I'm trying to find duplicate lines in a text file. Here's my code:

Code: Pascal  [Select]
  1. program Project1;
  2. {$mode objfpc}
  3. {$APPTYPE CONSOLE}
  4. {$CODEPAGE cp1252}
  5. uses
  6.   Classes, SysUtils, Types, rtlconsts;
  7. type
  8.   TMain = class
  9.     procedure ReadTextFile;
  10.   end;
  11. var
  12.   AClass: TMain;
  13.   TfIn: TextFile;
  14. procedure TMain.ReadTextFile;
  15. var
  16.   t: TDateTime;
  17.   h: thashedstringlist;
  18.   L: TStringList;
  19.   i: Integer;
  20.   tree: TStringToStringTree;
  21. begin
  22.   H:=THashedStringList.Create;
  23.   L:=TString.Create;
  24.   tree:=StringToStringList.Create(false);
  25.   try
  26.     h.LoadFromFile('C:\Users\Can\Desktop\test.txt');
  27.     L.LoadFromFile('C:\Users\Can\Desktop\test.txt');
  28.     tree.AddNameValues(L);
  29.     t:=Now;
  30.     for i:=1 to 100000000 do
  31.       h.IndexOfName('mhqjxlallgjzemwrglfl');
  32.     WriteLn(TimeToStr(now - t));
  33.     t:=Now;
  34.     for i:=1 to 100000000 do
  35.       if tree.Contains('mhqjxlallgjzemwrglfl') then
  36.         WriteLn(TimeToStr(now - t));
  37.   finally
  38.     L.Free;
  39.     tree.Free;
  40.     h.Free;
  41.   end;
  42. end;
  43. begin
  44.   AClass:=TMain.Create;
  45.   AClass.ReadTextFile;
  46.   ReadLn;
  47. end.

How can I use THashedStringList?

I'm getting these errors:
Quote
program.pas(17,6) Error: Identifier not found "thashedstringlist"
program.pas(17,23) Error: Error in type definition
program.pas(20,9) Error: Identifier not found "TStringToStringTree"
program.pas(20,28) Error: Error in type definition
program.pas(22,6) Error: Identifier not found "THashedStringList"
program.pas(23,6) Error: Identifier not found "TString"
program.pas(24,9) Error: Identifier not found "StringToStringList"
program.pas(26,7) Error: Illegal qualifier
program.pas(28,10) Error: Illegal qualifier
program.pas(31,9) Error: Illegal qualifier
program.pas(35,15) Error: Illegal qualifier
program.pas(39,10) Error: Illegal qualifier
program.pas(40,7) Error: Illegal qualifier
program.pas(48) Fatal: There were 13 errors compiling module, stopping
Fatal: Compilation aborted
Error: C:\lazarus\fpc\3.0.4\bin\x86_64-win64\ppcx64.exe returned an error exitcode

Dimitrios Chr. Ioannidis

  • Jr. Member
  • **
  • Posts: 83
    • Nephelae
Re: Need help with THashedStringList
« Reply #1 on: April 18, 2019, 02:31:31 pm »
You missed to add the IniFiles ( in which the THashedStringList resides ) unit to your uses clause.

i.e.

Code: Pascal  [Select]
  1. uses
  2.   Classes, SysUtils, Types, rtlconsts, IniFiles;

Dimitrios Chr. Ioannidis
http://www.nephelae.eu

nikel

  • Jr. Member
  • **
  • Posts: 99
Re: Need help with THashedStringList
« Reply #2 on: April 18, 2019, 03:28:32 pm »
Hi, thanks for the reply. I added Inifiles to uses clause but now I'm getting errors for TStringToStringTree and TString. And where can I find which units to add in the future?
« Last Edit: April 18, 2019, 03:33:00 pm by nikel »

Dimitrios Chr. Ioannidis

  • Jr. Member
  • **
  • Posts: 83
    • Nephelae
Re: Need help with THashedStringList
« Reply #3 on: April 18, 2019, 03:38:56 pm »
And where can I find which units to add in the future?

You can use the following link Index of all identifiers in package 'fcl'.

Click on an identifier and on the top right you can read the unit it is in.

EDIT: Forgot to mention the Search the documentation page.
« Last Edit: April 18, 2019, 03:44:42 pm by Dimitrios Chr. Ioannidis »
Dimitrios Chr. Ioannidis
http://www.nephelae.eu

nikel

  • Jr. Member
  • **
  • Posts: 99
Re: Need help with THashedStringList
« Reply #4 on: April 18, 2019, 03:47:18 pm »
That helped a lot. Thanks again.