summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGraeme Geldenhuys <graeme@mastermaths.co.za>2009-09-30 15:43:50 +0200
committerGraeme Geldenhuys <graeme@mastermaths.co.za>2009-09-30 15:43:50 +0200
commit8d28710dc1e228bfa8f669072db0bc2fe6a9a80f (patch)
treed245ff00dcaef594207fca6dd00091f907b2b229 /src
parent8f407a348cc872e90011df94bfb4dbd99fe28e51 (diff)
downloadfpGUI-8d28710dc1e228bfa8f669072db0bc2fe6a9a80f.tar.xz
Reimplement the ReadDictionary() method
* Internal dictionary storage is change from TList to TStringList * Global dictionary is also changed to TStringList type Signed-off-by: Graeme Geldenhuys <graeme@mastermaths.co.za>
Diffstat (limited to 'src')
-rw-r--r--src/HelpFile.pas48
-rw-r--r--src/HelpTopic.pas28
2 files changed, 35 insertions, 41 deletions
diff --git a/src/HelpFile.pas b/src/HelpFile.pas
index 1ef1fe9e..1b037931 100644
--- a/src/HelpFile.pas
+++ b/src/HelpFile.pas
@@ -28,21 +28,15 @@ type
protected
_Data: pointer;
_DataLen: longint;
-
_pSlotData: pInt16;
_SlotDataSize: longint;
-
_FileName: string;
_Title: string;
_Header: THelpFileHeader;
-
_Topics: TList; // of TTopic
-
- _Dictionary: TList; // pointers to strings.
-
+ _Dictionary: TStringList;
_SlotOffsets: Int32ArrayPointer;
_Index: TStringList;
-
_SearchTable: TSearchTable;
procedure InitMembers;
@@ -110,8 +104,7 @@ begin
_pSlotData := nil;
_SlotDataSize := 0;
-// _Dictionary:= TStringList.Create;
- _Dictionary:= TList.Create;
+ _Dictionary:= TStringList.Create;
_Topics:= TList.Create;
_Index:= TStringList.Create;
end;
@@ -220,14 +213,13 @@ begin
for TopicIndex:= 0 to _Topics.Count - 1 do
TTopic( _Topics[ TopicIndex ] ).Destroy;
- _Topics.Destroy;
-
- _Index.Destroy;
+ _Topics.Free;
- _Dictionary.Destroy;
+ _Index.Free;
- _SearchTable.Destroy;
+ _Dictionary.Free;
+ _SearchTable.Free;
end;
procedure THelpFile.ReadContents;
@@ -236,11 +228,11 @@ var
EntryIndex: longint;
pEntry: pTTOCEntryStart;
begin
- _Topics.Capacity:= _Header.ntoc;
+ _Topics.Capacity := _Header.ntoc;
pEntry:= _Data + _Header.tocstart;
- for EntryIndex:= 0 to integer( _Header.ntoc ) - 1 do
+ for EntryIndex := 0 to integer( _Header.ntoc ) - 1 do
begin
Topic:= TTopic.Create( _Data,
_Header,
@@ -252,24 +244,28 @@ begin
_Topics.Add( Topic );
- inc( pEntry, pEntry ^. Length );
+ inc( pEntry, pEntry^.Length );
end;
end;
procedure THelpFile.ReadDictionary;
var
i: longint;
- Len: int8;
p: pbyte;
+ c: array[0..255] of char;
+ b: byte;
+ s: string;
begin
- P:= _Data + _Header.dictstart;
- for i:= 0 to integer( _Header.ndict ) - 1 do
+ p := _Data + _Header.dictstart; // set starting position
+ for i := 0 to _header.ndict-1 do
begin
- Len:= p^ - 1;
- p^ := Len; // adjust so we can use as a string
-// S:= StrNPas( P, RecordLen-1 );
- _Dictionary.Add( P );
- inc( P, Len + 1 );
+ FillChar(c, sizeof(c),0); // fill string with NUL chars
+ Move(p^, b, sizeof(b)); // read string length value
+ Inc(p, sizeof(b)); // move pointer
+ Move(p^, c, b-1); // read string of dictionary
+ Inc(p, b-1); // move pointer
+ s := StrPas(@c);
+ _Dictionary.Add(s);
end;
end;
@@ -381,7 +377,7 @@ end;
function THelpFile.GetDictionaryWord( Index: longint ): string;
begin
- Result := pstring( _Dictionary[ Index ] )^;
+ Result := _Dictionary[Index];
end;
Initialization
diff --git a/src/HelpTopic.pas b/src/HelpTopic.pas
index a4600220..682272a3 100644
--- a/src/HelpTopic.pas
+++ b/src/HelpTopic.pas
@@ -50,7 +50,7 @@ Type
_NumSlots: longint;
_NumSlotsUsed: longint;
_Title: string;
- _GlobalDictionary: TList;
+ _GlobalDictionary: TStringList;
_ShowInContents: boolean;
_ContentsLevel: integer;
@@ -81,10 +81,10 @@ Type
public
constructor Create( FileData: pointer;
const FileHeader: THelpFileHeader;
- Dictionary: TList;
+ Dictionary: TStringList;
pTOCEntry: pTTOCEntryStart );
- destructor destroy; override;
+ destructor Destroy; override;
property Title: string read GetTitle write SetTitle;
procedure SetTitleFromMem( const p: pointer; const Len: byte );
@@ -169,7 +169,7 @@ end;
constructor TTopic.Create( FileData: pointer;
const FileHeader: THelpFileHeader;
- Dictionary: TList;
+ Dictionary: TStringList;
pTOCEntry: pTTOCEntryStart );
var
pExtendedInfo: pExtendedTOCEntry;
@@ -179,28 +179,26 @@ var
XY: THelpXYPair;
p: pbyte;
- Flags: byte;
-
+ lFlags: byte;
pSlotOffsets: Int32ArrayPointer;
pSlotData: pSlotHeader;
-
Slot: THelpTopicSlot;
begin
_Title := '';
- _GlobalDictionary:= Dictionary;
+ _GlobalDictionary := Dictionary;
_ContentsGroupIndex := 0;
_pTOCEntry := pTOCEntry;
_NumSlots:= pTOCEntry^.numslots;
- GetMem( _Slots, _NumSlots * sizeof( THelpTopicSlot ) );
+ GetMem( _Slots, _NumSlots * sizeof(THelpTopicSlot));
_NumSlotsUsed := 0;
- Flags:= _pTOCEntry ^. flags;
+ lFlags:= _pTOCEntry^.flags;
p:= pInt8( _pTOCEntry ) + sizeof( TTOCEntryStart );
- if ( Flags and TOCEntryExtended ) > 0 then
+ if ( lFlags and TOCEntryExtended ) > 0 then
begin
pExtendedInfo := pExtendedTOCEntry( p );
inc( p, sizeof( TExtendedTOCEntry ) );
@@ -256,8 +254,8 @@ begin
else
Title:= '(No title)';
- _ContentsLevel:= ( Flags and $f );
- _ShowInContents:= Flags and TOCEntryHidden = 0;
+ _ContentsLevel:= ( lFlags and $f );
+ _ShowInContents:= (lFlags and TOCEntryHidden) = 0;
if _ContentsLevel = 0 then
_ShowInContents := false; // hmmm....
end;
@@ -735,11 +733,11 @@ begin
if LocalDictIndex < Slot.LocalDictSize then
begin
// Normal word lookup
- GlobalDictIndex:= Slot.pLocalDictionary^[ LocalDictIndex ];
+ GlobalDictIndex := Slot.pLocalDictionary^[ LocalDictIndex ];
// normal lookup
if GlobalDictIndex < _GlobalDictionary.Count then
- Word := pstring( _GlobalDictionary[ GlobalDictIndex ] )^
+ Word := _GlobalDictionary[ GlobalDictIndex ]
else
Word := '';