Cache Images (use RequestHTTPImage event)

<< Click to Display Table of Contents >>

Navigation:  Programming > Load & Save >

Cache Images (use RequestHTTPImage event)

If you work with linked images it is possible to reuse one image for all occurrences in the file. Use the event RequestHTTPImage and a StringList "list". Of course, all list.Objects[] must be freed at some time later.

 

procedure TForm1.WPRichText1RequestHTTPImage(RTFData: TWPRTFDataCollection;

 Reader: TWPCustomTextReader; const LoadPath, URL: string;

 TextObject: TWPTextObj; var Ok: Boolean);

var i : Integer;

begin

i := list.IndexOf( LoadPath  + URL );

if i>=0 then

begin

   TextObject.ObjRef := TWPObject(list.Objects[i]);

end else

begin

   TextObject.LoadObjFromFile( LoadPath + URL  );

   list.AddObject( LoadPath  + URL, TextObject.ObjRef );

end;

OK := true;

end;