我想弄一个Delphi版的edge浏览器【打开百度翻译】点击上面的 【上传文档】按钮的代码:
所以,看了下面的文章https://blog.csdn.net/zhou752947/article/details/109542365
结果 编译时卡在了下面的地方!所以来求助,谢谢。
E2023 Function needs result type
[Delphi] 纯文本查看 复制代码 unit Unit2;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs,
Winapi.WebView2, Winapi.ActiveX, Vcl.Edge, Vcl.StdCtrls, Vcl.ExtCtrls;
type
TForm2 = class(TForm)
EdgeBrowser1: TEdgeBrowser;
Panel1: TPanel;
Edit1: TEdit;
Button1: TButton;
Button2: TButton;
Button3: TButton;
Button4: TButton;
procedure Button1Click(Sender: TObject);
procedure EdgeBrowser1ExecuteScript(Sender: TCustomEdgeBrowser;
AResult: HRESULT; const AResultObjectAsJson: string);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form2: TForm2;
// Result: Boolean;
implementation
{$R *.dfm}
function getJavaScript(ScriptPath:string; Args:array of string);
var AList:TStringList;
I:Integer;
begin
Alist:= TStringList.Create;
Alist.LoadFromFile(ScriptPath, TEncoding.UTF8);
for I := Low(Args) to High(Args) do
begin
//StringReplace函数 需要引用 System.SysUtils
AList.Text := StringReplace(AList.Text, '%s', Args[I], []);
end;
Result:= AList.Text;
AList.Free;
end;
procedure TForm2.Button1Click(Sender: TObject);
begin
EdgeBrowser1.Navigate(Edit1.Text);
end;
procedure TForm2.Button2Click(Sender: TObject);
var AText:string;
begin
AText:= getJavaScript('Test1.js', ['upload-btn', '123456']);
EdgeBrowser1.ExecuteScript(AText);
end;
procedure TForm2.EdgeBrowser1ExecuteScript(Sender: TCustomEdgeBrowser;
AResult: HRESULT; const AResultObjectAsJson: string);
begin
EdgeBrowser1.ExecuteScript('我的Javascript脚本');
//ScriptResult:= AResultObjectAsJson;
end;
end.
|