| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- unit TestController;
- interface
- uses
- ceflib;//ÆäËü
- type
- TExtension = class(TCefv8HandlerOwn)
- private
- FTestParam: ustring;
- protected
- function Execute(const name: ustring; const obj: ICefv8Value;
- const arguments: TCefv8ValueArray; var retval: ICefv8Value;
- var exception: ustring): Boolean; override;
- end;
- TRiitExtension = class
- public
- class function HelloWorld: string;
- end;
- implementation
- function TExtension.Execute(const name: ustring; const obj: ICefv8Value;
- const arguments: TCefv8ValueArray; var retval: ICefv8Value;
- var exception: ustring): Boolean;
- begin
- // if(name = 'SetTestParam') then
- // begin
- // // Handle the SetTestParam native function by saving the string argument
- // // into the local member.
- // if (Length(arguments) <> 1) or (not arguments[0].IsString) then
- // begin
- // Result := false;
- // Exit;
- // end;
- // FTestParam := arguments[0].GetStringValue;
- // Result := true;
- // end
- // else if(name = 'GetTestParam') then
- // begin
- // // Handle the GetTestParam native function by returning the local member
- // // value.
- // retval := TCefv8ValueRef.CreateString(Ftestparam);
- // Result := true;
- // end
- // else if (name = 'GetTestObject') then
- // begin
- // // Handle the GetTestObject native function by creating and returning a
- // // new V8 object.
- // retval := TCefv8ValueRef.CreateObject(nil);
- // // Add a string parameter to the new V8 object.
- // retval.SetValueByKey('param', TCefv8ValueRef.CreateString(
- // 'Retrieving a parameter on a native object succeeded.'));
- // // Add a function to the new V8 object.
- // retval.SetValueByKey('GetMessage',
- // TCefv8ValueRef.CreateFunction('GetMessage', Self));
- // Result := true;
- // end
- // else if(name = 'GetMessage') then
- // begin
- // // Handle the GetMessage object function by returning a string.
- // retval := TCefv8ValueRef.CreateString(
- // 'Calling a function on a native object succeeded.');
- // Result := true;
- // end else
- // Result := false;
- end;
- const
- code =
- 'var cef;'+
- 'if (!cef)'+
- ' cef = {};'+
- 'if (!cef.test)'+
- ' cef.test = {};'+
- '(function() {'+
- ' cef.test.__defineGetter__(''test_param'', function() {'+
- ' native function GetTestParam();'+
- ' return GetTestParam();'+
- ' });'+
- ' cef.test.__defineSetter__(''test_param'', function(b) {'+
- ' native function SetTestParam();'+
- ' if(b) SetTestParam(b);'+
- ' });'+
- ' cef.test.test_object = function() {'+
- ' native function GetTestObject();'+
- ' return GetTestObject();'+
- ' };'+
- '})();';
- { TRiitExtension }
- class function TRiitExtension.HelloWorld: string;
- begin
- Result := 'Hello World!';
- end;
- initialization
- // CefLoadLibDefault;
- //TCefRTTIExtension.Register('TestController', TRiitExtension);
- end.
|