登录 用户中心() [退出] 后台管理 注册
   
您的位置: 首页 >> SoftHub关联区 >> 主题: lazarus在macos里调用外部浏览器打开一个网址[zt]     [回主站]     [分站链接]
lazarus在macos里调用外部浏览器打开一个网址[zt]
clq
浏览(341) - 2020-10-31 14:33:27 发表 编辑

关键字:

[2024-02-07 00:54:18 最后更新]


lazarus在macos里调用外部浏览器打开一个网址

https://blog.csdn.net/qiaozhangchi/article/details/107978054

----------------------------------------------------------------


lazarus
跨平台free pascal语言ide工具,社区 http://www.fpccn.com/

下载 ftp://freepascal.dfmk.hu/pub/lazarus/

https://sourceforge.net/projects/lazarus/files/

号称一次编码,到处编译,window linux macos 等各种平台都可用。borland的windows下的delphi也是pascal开发工具但是收费,开源的lazarus免费用用挺好

大的项目不说,小的工具还是值得一用,今天整了一段跨平台代码到macos环境试一下

首先要安装,体验结果ftp下载网址网速不快,晚上的时候http网址也不快到了早上没人用http网址还算比较快

安装完成,根据教程先整合分体式ide为1体式,谁知安装了anchordockingdsgn.lpk相关dock搜索出来的3个包之后,重新构建重启后还是没变化?

原来是重新构建的文件不在系统路径,没权限写进去,在~/.lazarus/bin/lazarus,自己手动复制到/Library/Lazarus/目录下覆盖下即可,修改sourceeditor.pp和sourceeditor.lfm解决源代码编辑器不能输入中文也是注意提前给权限写文件否则只读文件不能编辑


procedure TForm1.FormCreate(Sender: TObject);
var
IniFile: TIniFile;
begin
if FileExists(ExtractFilePath(ParamStr(0)) + 'Test.ini') then
begin
IniFile := TIniFile.Create(ExtractFilePath(ParamStr(0)) + 'Test.ini');
Edit1.Text := IniFile.readString('item', 'browser', '');
IniFile.Free;
end;
StatusBar1.SimpleText := '已经加载:' + ExtractFilePath(ParamStr(0)) + 'Test.ini';
end;

procedure TForm1.Button1Click(Sender: TObject);
var
IniFile: TIniFile;
begin
IniFile := TIniFile.Create(ExtractFilePath(ParamStr(0)) + 'Test.ini');
IniFile.writeString('item', 'browser', Edit1.Text);
IniFile.Free;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
if OpenDialog1.Execute then
Edit1.Text := OpenDialog1.FileName;
end;

procedure TForm1.correctBtnClick(Sender: TObject);
var
IniFile: TIniFile;
begin
if FileExists(Edit1.Text) then
if '.desktop' = ExtractFileExt(Edit1.Text) then
begin
IniFile := TIniFile.Create(Edit1.Text);
Edit1.Text := IniFile.ReadString('Desktop Entry', 'Exec', '');
IniFile.Free;
end;
if '.app' = ExtractFileExt(Edit1.Text) then
begin
OpenDialog1.InitialDir := Edit1.Text;
if OpenDialog1.Execute then
Edit1.Text := OpenDialog1.FileName;
end;
end;

procedure TForm1.Edit1Change(Sender: TObject);
begin
if pos(' ', Edit1.Text) > 0 then
StatusBar1.SimpleText :=
'请检查是否存在空格,请把空格和之后的参数去掉';
if '.desktop' = ExtractFileExt(Edit1.Text) then
StatusBar1.SimpleText :=
'linux环境请检查是否是.desktop文件,是的话需要修正';
if '.app' = ExtractFileExt(Edit1.Text) then
StatusBar1.SimpleText :=
'macos环境请检查是否是.app目录, 是的话需要修正';

if FileExists(Edit1.Text) then
begin
attr := FileGetAttr(Edit1.Text);
if (attr and faSymLink) > 0 then
StatusBar1.SimpleText :=
'如果不能正常运行,请检查是否是链接,尝试原文件.文件属性:'+IntToStr(attr);
end;
end;

//x-www-browser http://www.baidu.com
procedure TForm1.testBtnClick(Sender: TObject);
var
Process: TProcess;
begin
if pos(' ', Edit1.Text) > 0 then
StatusBar1.SimpleText := '请检查可执行文件路径是否存在空格';
Process := TProcess.Create(nil);
try
//ExecuteProcess The calling process runs synchronously: it 'hangs' until the external program has finished
//ExecuteProcess(MarshaledAString(UTF8String(Edit1.Text)),'https://blog.csdn.net/qiaozhangchi',[ExecInheritsHandles]);
// if RunCommand(Edit1.Text,['https://blog.csdn.net/qiaozhangchi'],s) then
Process.InheritHandles := False;
Process.Options := [];
Process.ShowWindow := swoShow;
Process.Executable := Edit1.Text;
Process.Parameters.Add('https://blog.csdn.net/qiaozhangchi');
Process.Execute;
StatusBar1.SimpleText := '已经执行';
except
on E: EOSError do
StatusBar1.SimpleText :='请检查文件路径是否有空格或不能直接执行的后缀名,请修正';
end;
Process.Free;
end;

跨平台代码就是好,这一段代码包含几个知识点

ini文件读写
TProcess启动另外程序
打开文件对话框
状态栏控件




总数:0 页次:1/0 首页 尾页  
总数:0 页次:1/0 首页 尾页  


所在合集/目录
lazarus开发 更多



发表评论:
文本/html模式切换 插入图片 文本/html模式切换


附件:



NEWBT官方QQ群1: 276678893
可求档连环画,漫画;询问文本处理大师等软件使用技巧;求档softhub软件下载及使用技巧.
但不可"开车",严禁国家敏感话题,不可求档涉及版权的文档软件.
验证问题说明申请入群原因即可.

Copyright © 2005-2020 clq, All Rights Reserved
版权所有
桂ICP备15002303号-1