0
votes

I want to use TPerlRegExp (from http://www.regular-expressions.info/delphi.html, halfway down the page) in my project in Delphi 2009.

I added PerlRegEx.pas and pcre.pas to my project group, and put 'PerlRegEx' in my uses list.

When I compile, I get the following errors:

[DCC Error] PerlRegEx.pas(305): E2003 Undeclared identifier: 'pcre_dispose'

[DCC Error] PerlRegEx.pas(533): E2003 Undeclared identifier: 'pcre_dispose'

[DCC Fatal Error] test.dpr(21): F2063 Could not compile used unit '..\Shared\Classes\TPerlRegEx\PerlRegEx.pas'

When I comment out the lines using 'pcre_dispose', it compiles ok. But I don't want to create memory leaks by not freeing things of course...so what might be causing this?

Anyone who has an idea?

Thanks a lot!

1
Which one of them have you downloaded ? Could you include the exact link to the version you've used ?TLama
I tried with both, and both give the same problem. Currently I am including the files from the latest version: regular-expressions.info/download/TPerlRegEx.zip.SonOfGrey
Jedi Code Library also have wrapper around PCRE. Tried it ?Arioch 'The
@Arioch'The Didn't try it yet, because I have a much older installation of Jedi in use for other projects that I can't just update without consequences. And I suppose I can't use different versions side by side. Or can I install just the PCRE wrapper component?SonOfGrey
@Arioch'The Why do you suggest JCL?! OP wants to use the excellent TPerlRegEx.David Heffernan

1 Answers

1
votes

Step by step for a working install (from the download link you provided in the comments to the original question):

Extract the Zip file into a folder. I used E:\Code\PerlRegEx\XE2, because I have a non-Unicode version installed for D2007 already.

Start a new console project with File->New->Other->Console App.

Use Project->Options->Compiler from the IDE's main menu, and add the path location from above into the Search Path. Paste the following code to replace everything in the Code Editor:

program Project2;

{$APPTYPE CONSOLE}

{$R *.res}

uses
  System.SysUtils, PerlRegex;

var
  Regex: TPerlRegex;

begin
  try
    Regex := TPerlRegex.Create;
    try
      Regex.Subject := 'This is a test of TPerlRegex';
      Regex.RegEx := '\btest\b';
      if Regex.Match then
        WriteLn('Found match: ' + Regex.MatchedText)
      else
        WriteLn('Can''t be! No match found!');
      ReadLn;
    finally
      Regex.Free;
    end;
  except
    on E: Exception do
      Writeln(E.ClassName, ': ', E.Message);
  end;
end.

As you can see, I've used a very complex test of the functionality of TPerlRegex for this test case. :-)

If the above works for you, and you're still having problems in your own project:

  1. Check your old project for a reference to an old version of TPerlRegex (another folder in the search or library path, an entry in Tools->Options->Environment->Library Path).

  2. Check the uses clause (you can use Search->Find in Files, check All Files in Project) for PerlRegex.

  3. Make sure you followed the exact steps above: Add PerlRegex's folders to your Project->Compiler->Search Path settings, add PerlRegex to the uses clause of the unit you want to use it in. If it works in the code from my example on your machine, but doesn't in your other project, the problem is there