当前位置: 首页 > news >正文

lazarus:LCL 嵌入 fpwebview 组件,做一个简单浏览器

从 https://github.com/PierceNg/fpwebview 下载 fpwebview-master.zip 简单易用。

先请看 \fpwebview-master\README.md

cd \lazarus\projects\fpwebview-master\demo\lclembed

修改 lclembed.lpr  如下,将 fphttpapp. 注释掉,因为我用不上 a simple webserver。

program lclembed;{$mode objfpc}{$H+}
{$ifdef darwin}{$linklib libwebview}{$endif}
{$ifdef mswindows}{$linklib libwebview}{$endif}uses{$IFDEF UNIX}cmem, cthreads,{$ENDIF}Interfaces, Forms, math,classes, fphttpapp, fpwebfile,guiform;{$R *.res}typeTWebServerThread = class(TThread)protectedprocedure Execute; override;publicconstructor Create(CreateSuspended: boolean);end;constructor TWebServerThread.Create(CreateSuspended: boolean);
begininherited Create(CreateSuspended);FreeOnTerminate := true;
end;procedure TWebServerThread.Execute;
begin
//fphttpapp.Application.Run;
end;varcurrDir: String;begin{ Set math masks. libwebview throws at least one of these from somewhere deep inside. }SetExceptionMask([exInvalidOp, exDenormalized, exZeroDivide, exOverflow, exUnderflow, exPrecision]);{ Set up embedded webserver. }GetDir(0, currDir);TSimpleFileModule.BaseDir := currDir + '/htdocs';TSimpleFileModule.RegisterDefaultRoute;TSimpleFileModule.IndexPageName := 'index.html';MimeTypesFile := 'mime.types';
//fphttpapp.Application.Port := 8000;
//fphttpapp.Application.Threaded := true;
//fphttpapp.Application.Initialize;
//TWebServerThread.Create(false);{ Set up LCL application. }RequireDerivedFormResource:=True;Forms.Application.Scaled:=True;Forms.Application.Initialize;Forms.Application.CreateForm(TForm1, Form1);Forms.Application.Run;
end.

修改 guiform.pas 如下,我增加一个Edit1 和 Button1

usesClasses, SysUtils, StrUtils,procedure TForm1.Button1Click(Sender: TObject);
var url: String;
beginurl:= Edit1.Text;if AnsiStartsStr('192.', url) then url:= 'http://' + Trim(url)else if AnsiStartsStr('http', url) then url:= Trim(url)else url:= 'https://' + Trim(url);webview_navigate(wvHandle, PAnsiChar(url));end;procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: char);
beginif key = #13 then Button1Click(Sender);
end;其它代码暂时不改变

编写 winbuild.bat  如下,并运行。

@echo offecho Set up FPC executable path.
set fpcexe=D:\lazarus\fpc\3.2.2\bin\x86_64-win64\fpc.exe
if not exist "%fpcexe%" (echo ERROR: Edit this batch file to set up location of fpc.exeexit /b 1
)
echo "%fpcexe%"echo Building...
copy "..\..\dll\x86_64\libwebview.a" .
copy "..\..\dll\x86_64\webview.dll" .
copy "..\..\dll\x86_64\WebView2Loader.dll" .

点击菜单:运行:构建,构建成功后再点击 运行

或者 运行 lclembed.exe

http://www.lryc.cn/news/301019.html

相关文章:

  • c++类和对象新手保姆级上手教学(上)
  • 可变参数(c/c++)
  • 【数据结构】图
  • 32.3K Star,再见 Postman,这款开源 API 客户端更香
  • Python循环语句——continue和break
  • C++面向对象程序设计-北京大学-郭炜【课程笔记(三)】
  • Linux:搭建docker私有仓库(registry)
  • 用HTML、CSS和JS打造绚丽的雪花飘落效果
  • 订餐|网上订餐系统|基于springboot的网上订餐系统设计与实现(源码+数据库+文档)
  • 从零开始学howtoheap:解题西湖论剑Storm_note
  • Rust 基本环境安装
  • 【电源】POE系统供电原理(二)
  • GPU独显下ubuntu屏幕亮度不能调节解决方法
  • Linux篇:网络基础1
  • RK3568笔记十七:LVGL v8.2移植
  • C#系列-C#访问MongoDB+redis+kafka(7)
  • (12)Hive调优——count distinct去重优化
  • 记录 | 验证pytorch-cuda是否安装成功
  • LeetCode 239.滑动窗口的最大值 Hot100 单调栈
  • 463. Island Perimeter(岛屿的周长)
  • 如何解决缓存和数据库的数据不一致问题
  • linux系统下vscode portable版本的python环境搭建003:venv
  • 使用TinyXML-2解析XML文件
  • Linux:docker在线仓库(docker hub 阿里云)基础操作
  • C语言程序设计(第四版)—习题7程序设计题
  • ZCC6982-同步升压充双节锂电池充电芯片
  • 定时器(基本定时器、通用定时器、高级定时器)
  • 009集——磁盘详解——电脑数据如何存储在磁盘
  • 鸿蒙开发-HarmonyOS UI架构
  • Flutter 动画(显式动画、隐式动画、Hero动画、页面转场动画、交错动画)