@@ -35,6 +35,7 @@ function LoadEntities(ANpp: TApplication; ASet: string = 'HTML 4'): TStringList;
3535 Line, Value , Entity: string;
3636 i, Separation, CodePoint: integer;
3737 Reading: boolean;
38+ ErrMsg: string;
3839begin
3940// DebugWrite('LoadEntities', Format('Set "%s"', [ASet]));
4041
@@ -48,10 +49,15 @@ function LoadEntities(ANpp: TApplication; ASet: string = 'HTML 4'): TStringList;
4849 Result := TStringList(EntityLists.Objects[i]);
4950 end else begin
5051 IniFile := IncludeTrailingPathDelimiter(GetApplication.ConfigFolder) + ' HTMLTag-entities.ini' ;
52+ ErrMsg := Format(' HTMLTag-entities.ini must be saved to' #13 #10 ' %s' , [ExtractFileDir(IniFile)]);
5153 if not FileExists(IniFile) then
5254 IniFile := ChangeFilePath(IniFile, TSpecialFolders.DLL);
55+ ErrMsg := Concat(ErrMsg, Format(#13 #10 ' or to' #13 #10 ' %s' , [ExtractFileDir(IniFile)]));
5356 if not FileExists(IniFile) then begin
54- raise Exception.CreateFmt(' Unable to find entities file at "%s".' , [IniFile]);
57+ MessageBox(ANpp.WindowHandle, PChar(ErrMsg), PChar(' Missing Entities File' ), MB_ICONERROR);
58+ FreeAndNil(EntityLists);
59+ Result := nil ;
60+ Exit;
5561 end else begin
5662 Result := TStringList.Create;
5763 Result.NameValueSeparator := ' =' ;
@@ -164,6 +170,10 @@ function DoEncodeEntities(var Text: WideString; const Entities: TStringList; con
164170 EntitiesReplaced: integer;
165171begin
166172 EntitiesReplaced := 0 ;
173+ if not Assigned(Entities) then begin
174+ Result := EntitiesReplaced;
175+ Exit;
176+ end ;
167177
168178 for CharIndex := Length(Text) downto 1 do begin
169179 EntityIndex := Entities.IndexOfObject(TObject(integer(Ord(Text[CharIndex]))));
@@ -218,6 +228,9 @@ procedure DecodeEntities(const Scope: TEntityReplacementScope = ersSelection);
218228 Entities := LoadEntities(npp);
219229 end ;
220230
231+ if not Assigned(Entities) then
232+ Exit;
233+
221234 Text := doc.Selection.Text;
222235
223236 CharIndex := Pos(' &' , Text);
0 commit comments