tags:

views:

73

answers:

2

Dear Experts:

We are tring to use in delphi a pas file generated by Free Pascal. The link is at: http://www.markwatson.com/opensource/FastTag_Pascal.zip

While testing, it prompts InValidPointer. Please look at the following error line in debugger.

interface

procedure ReadLexicon;
type sarray = array[1..12] of string;
type big_sarray = array[1..1000] of string; { used for word lists and tags: limit on size of input text }
type psarray = ^sarray;

{function GetTagList(word: string): psarray;}
procedure TagWordList(wordList : big_sarray; var tags : big_sarray);

implementation

uses SysUtils, Classes;

 {       Hash Table Support - copied from FreePascal source: benchmork shootout examples }

type
   THashEntryPtr = ^THashEntryRec;
   THashEntryRec = record
      name : string;
      number : psarray;
      next : THashEntryPtr;
   end;

const
   TABLE_SIZE = 100000;

...
...
...
function GetTagList(word: string): psarray;
var
ret : psarray;
ok : boolean;
begin
 ok := localHash.fetch(word, ret);
 if ok then GetTagList := ret else GetTagList := nil;
end;

procedure TagWordList(wordList : big_sarray; var tags : big_sarray);
var i : integer;
    x : real;
    psa : psarray;
    lastThreeChars : string;
    lastTwoChars : string;
    lastChar : string;
    firstTwoChars : string;
    tagFirstTwoChars : string;
    begin
 for i := 0 to length(wordList) do
  begin
   **psa := GetTagList(wordList[i]);///// EInvalidPointer ERROR** 
   if psa <> nil then tags[i] := psa^[1] else tags[i] := '???';
  end;

...
...
...

How can we fix it. Thank you very much in advance.

+3  A: 

There are at least two errors I can find in the TagWordList procedure.

  1. for i := 0 to length(wordList) do, the array is 1-based so the loop has to start with 1.
  2. A bit later there is a check if i > 0 that fails for the same reason.

It could also be a wrong definition of the type big_sarray = array[1..1000] of string;. If you change that to a 0-based array it might work.

Jens Mühlenhoff
+3  A: 

The original source doesn't set any compiler mode, and so the default TP like mode is active, meaning string=shortstring.

Replace, in the entire source string with shortstring and it will probably work.

Marco van de Voort
Dear Marco van de Voort, it works now, though i still do not know why it should be replaced as you advised, and it seems very slow to load that lexicon file and run. Thank you very much.