htmlloadlinkdemo.lpr 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. program htmlloadlinkdemo;
  2. {$mode objfpc}
  3. uses
  4. Classes, Web, p2jsres;
  5. {$R left.png}
  6. {$R right.png}
  7. {$R up.png}
  8. {$R down.png}
  9. Const
  10. MaxImages = 4;
  11. ImageResources : Array[1..MaxImages] of string = ('up','right','down','left');
  12. Var
  13. Img : TJSHTMLImageElement;
  14. CurrentImage: Integer = 1;
  15. Procedure ShowCurrentImage;
  16. Var
  17. aInfo : TResourceInfo;
  18. begin
  19. if not GetResourceInfo(ImageResources[CurrentImage],aInfo) then
  20. Writeln('No info for image ',ImageResources[CurrentImage])
  21. else
  22. Img.Src:='data:'+aInfo.format+';base64,'+aInfo.Data;
  23. end;
  24. function RotateImage(aEvent: TJSMouseEvent): boolean;
  25. begin
  26. Result:=False;
  27. Inc(CurrentImage);
  28. if CurrentImage>MaxImages then
  29. CurrentImage:=1;
  30. ShowCurrentImage;
  31. end;
  32. procedure OnLoaded(const LoadedResources: array of String);
  33. Var
  34. S : String;
  35. begin
  36. // Some info
  37. for S in LoadedResources do
  38. Writeln('Found resource: ',S);
  39. Img.OnClick:=@RotateImage;
  40. ShowCurrentImage;
  41. end;
  42. procedure OnLoadFailed(const aError: string);
  43. begin
  44. window.alert('Failed to load resources : '+AError)
  45. end;
  46. begin
  47. SetResourceSource(rsHTML);
  48. Img:=TJSHTMLImageElement(Document.GetElementByID('theimage'));
  49. LoadHTMLLinkResources('htmlloadlinkdemo-res.html',@OnLoaded,@OnLoadFailed);
  50. end.