本帖最后由 冥界3大法王 于 2021-10-21 10:44 编辑
@Jack2002
用的是Delphi 11(即15)+JS Engine + Edge 控件(和你说的那个差不多((需要安装Microsoft Edge Dev))外加一个单独的WebView2Loader.dll
https://wwi.lanzoui.com/i9brYvl5agd(包括全部源码 和 编译后的EXE)
不知为啥,楼上这些位朋友的代码都报错呢,下面是部分源码:
[Delphi] 纯文本查看 复制代码
procedure TFormMain.ButtonRunClick(Sender: TObject);
var
MyObject: JsValueRef;
Result: JsValueRef;
begin
if PageControl.ActivePage = TabSheetSimple then
with Engine do
try
MemoResultSimple.Clear;
MemoResultSimple.Text := ConvertToString(RunScript(MemoScriptSimple.Text))
except
on E: Exception do
ShowException(MemoResultSimple, E);
end
else if PageControl.ActivePage = TabSheetFunction then
with Engine do
try
MemoResultFunction.Clear;
MemoResultFunction.Text := ConvertToString(RunScript(MemoScriptFunction.Text))
except
on E: Exception do
ShowException(MemoResultFunction, E);
end
else if PageControl.ActivePage = TabSheetNativeFunction then
with Engine do
try
MemoResultNativeFunction.Clear;
RegisterFunction('NativeFunction');
MemoResultNativeFunction.Text := ConvertToString(RunScript(MemoScriptNativeFunction.Text));
except
on E: Exception do
ShowException(MemoResultNativeFunction, E);
end
else if PageControl.ActivePage = TabSheetNativeMethod then
with Engine do
try
MemoResultNativeMethod.Clear;
MyObject := CreateObject;
SetProperty(GlobalObject, 'MyObject', MyObject);
RegisterMethod(MyObject, 'NativeMethod');
MemoResultNativeMethod.Text := ConvertToString(RunScript(MemoScriptNativeMethod.Text))
except
on E: Exception do
ShowException(MemoResultNativeMethod, E);
end
else if PageControl.ActivePage = TabSheetVariable then
with Engine do
try
MemoResultVariable.Clear;
SetProperty(GlobalObject, 'MyVariable', CreateString('Hello'));
MemoResultVariable.Text := ConvertToString(RunScript(MemoScriptVariable.Text));
ShowMessage('MyVariable=' + ConvertToString(GetProperty(GlobalObject, 'MyVariable')));
except
on E: Exception do
ShowException(MemoResultVariable, E);
end
else if PageControl.ActivePage = TabSheetProperty then
with Engine do
try
MemoResultProperty.Clear;
MyObject := CreateObject;
SetProperty(GlobalObject, 'MyObject', MyObject);
SetProperty(MyObject, 'MyProperty', CreateString('Hello'));
MemoResultProperty.Text := ConvertToString(RunScript(MemoScriptProperty.Text));
ShowMessage('MyObject.MyProperty=' + ConvertToString(GetProperty(MyObject, 'MyProperty')));
except
on E: Exception do
ShowException(MemoResultProperty, E);
end
else if PageControl.ActivePage = TabSheetFunctionCall then
with Engine do
try
MemoResultFunctionCall.Clear;
RunScript(MemoScriptFunctionCall.Text);
Result := Call('hello', [UndefinedValue {this}, CreateString('Erik')]);
MemoResultFunctionCall.Text := ConvertToString(Result);
except
on E: Exception do
ShowException(MemoResultFunctionCall, E);
end
end;
|