TestController.pas 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. unit TestController;
  2. interface
  3. uses
  4. ceflib;//ÆäËü
  5. type
  6. TExtension = class(TCefv8HandlerOwn)
  7. private
  8. FTestParam: ustring;
  9. protected
  10. function Execute(const name: ustring; const obj: ICefv8Value;
  11. const arguments: TCefv8ValueArray; var retval: ICefv8Value;
  12. var exception: ustring): Boolean; override;
  13. end;
  14. TRiitExtension = class
  15. public
  16. class function HelloWorld: string;
  17. end;
  18. implementation
  19. function TExtension.Execute(const name: ustring; const obj: ICefv8Value;
  20. const arguments: TCefv8ValueArray; var retval: ICefv8Value;
  21. var exception: ustring): Boolean;
  22. begin
  23. // if(name = 'SetTestParam') then
  24. // begin
  25. // // Handle the SetTestParam native function by saving the string argument
  26. // // into the local member.
  27. // if (Length(arguments) <> 1) or (not arguments[0].IsString) then
  28. // begin
  29. // Result := false;
  30. // Exit;
  31. // end;
  32. // FTestParam := arguments[0].GetStringValue;
  33. // Result := true;
  34. // end
  35. // else if(name = 'GetTestParam') then
  36. // begin
  37. // // Handle the GetTestParam native function by returning the local member
  38. // // value.
  39. // retval := TCefv8ValueRef.CreateString(Ftestparam);
  40. // Result := true;
  41. // end
  42. // else if (name = 'GetTestObject') then
  43. // begin
  44. // // Handle the GetTestObject native function by creating and returning a
  45. // // new V8 object.
  46. // retval := TCefv8ValueRef.CreateObject(nil);
  47. // // Add a string parameter to the new V8 object.
  48. // retval.SetValueByKey('param', TCefv8ValueRef.CreateString(
  49. // 'Retrieving a parameter on a native object succeeded.'));
  50. // // Add a function to the new V8 object.
  51. // retval.SetValueByKey('GetMessage',
  52. // TCefv8ValueRef.CreateFunction('GetMessage', Self));
  53. // Result := true;
  54. // end
  55. // else if(name = 'GetMessage') then
  56. // begin
  57. // // Handle the GetMessage object function by returning a string.
  58. // retval := TCefv8ValueRef.CreateString(
  59. // 'Calling a function on a native object succeeded.');
  60. // Result := true;
  61. // end else
  62. // Result := false;
  63. end;
  64. const
  65. code =
  66. 'var cef;'+
  67. 'if (!cef)'+
  68. ' cef = {};'+
  69. 'if (!cef.test)'+
  70. ' cef.test = {};'+
  71. '(function() {'+
  72. ' cef.test.__defineGetter__(''test_param'', function() {'+
  73. ' native function GetTestParam();'+
  74. ' return GetTestParam();'+
  75. ' });'+
  76. ' cef.test.__defineSetter__(''test_param'', function(b) {'+
  77. ' native function SetTestParam();'+
  78. ' if(b) SetTestParam(b);'+
  79. ' });'+
  80. ' cef.test.test_object = function() {'+
  81. ' native function GetTestObject();'+
  82. ' return GetTestObject();'+
  83. ' };'+
  84. '})();';
  85. { TRiitExtension }
  86. class function TRiitExtension.HelloWorld: string;
  87. begin
  88. Result := 'Hello World!';
  89. end;
  90. initialization
  91. // CefLoadLibDefault;
  92. //TCefRTTIExtension.Register('TestController', TRiitExtension);
  93. end.