htmllinkdemo.lpr 888 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. program htmllinkdemo;
  2. {$mode objfpc}
  3. uses
  4. JS, Classes, SysUtils, 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. Inc(CurrentImage);
  27. if CurrentImage>MaxImages then
  28. CurrentImage:=1;
  29. ShowCurrentImage;
  30. end;
  31. begin
  32. SetResourceSource(rsHTML);
  33. Img:=TJSHTMLImageElement(Document.GetElementByID('theimage'));
  34. Img.OnClick:=@RotateImage;
  35. ShowCurrentImage;
  36. end.