GUI 应用程序中的空主窗体从 Delphi 转换为 Lazarus

发布于 2024-08-12 12:46:54 字数 1264 浏览 6 评论 0 原文

我已将 2 个 GUI 应用程序从 Delphi 转换为 Lazarus。 这两个应用程序都针对 Win32 平台、i386 进行编译,并带有 GUI。 主表单使用 Lazarus 工具转换,可以从 IDE 进行编辑。 但是当我运行这样的应用程序时,主窗体不会出现,只有空白窗体,没有任何控件。

我尝试对此进行调试。它运行初始化部分中的所有代码, 并运行 .lpr 项目中的代码,但 CreateForm() 中出现错误,因为 它不会在主窗体 OnCreate 事件中运行代码。在事件日志中我可以看到所有 我写入的文本在关闭此空表单后出现 '

.lpr 项目中的代码:

  Application.Initialize;
  AddToEventLogInfo('App.CreateForm');
  Application.CreateForm(TfrmTst, frmTst);
  AddToEventLogInfo('App.Run>');
  Application.Run;
  AddToEventLogInfo('<App.Run');

我检查了我是否能够从 Lazarus 创建简单的 GUI 应用程序,但两者都转换为 GUI 应用程序无法按预期运行。有什么问题吗?我错过了什么吗? 也许拉撒路写的众多警告和提示之一很重要?

当我运行我的应用程序时,Lazarus 写道:

  windres: warning: 14: "MAINICON": 1045: duplicate value
  windres: warning: 16: 1: 1045: duplicate value
  Project "Tst_fpc" successfully built. :)

编辑:

Lazarus 转换工具已转换 .dfm -> .lfm,但 .pas 文件存在一些问题。我必须手动:

  1. 将 Lazarus 单位添加到用途:

    用途 {$IFDEF FPC} LCLIntf、L 资源、 {$ENDIF}

  2. 条件编译Delphi形式{$R *.dfm}:

    {$IFNDEF FPC} {$R *.dfm} {$ENDIF}

  3. 在初始化代码中添加.lrs资源:

    初始化 {$IFDEF FPC} {$i myunit.lrs} {$ENDIF}

I have converted my 2 GUI apps from Delphi to Lazarus.
Both apps compile for Win32 platform, i386 and with GUI.
Main form were converted using Lazarus tool and can be edited from IDE.
But when I run such application main form does not appear, only blank form without any controls.

I tried to debug this. It runs all code in initialization sections,
and runs code from .lpr project, but something wrong happens in CreateForm() because
it doesn't run code in the main form OnCreate event. In event log I can see all
texts I write to it with '<App.Run' appearing after I close this empty form.

Code in .lpr project:

  Application.Initialize;
  AddToEventLogInfo('App.CreateForm');
  Application.CreateForm(TfrmTst, frmTst);
  AddToEventLogInfo('App.Run>');
  Application.Run;
  AddToEventLogInfo('<App.Run');

I checked that I am able to create simple GUI apps from the Lazarus, but both converted GUI
apps do not work as expected. What can be wrong? Have I missed something?
Maybe one of many warnings and hints Lazarus write is important?

When I run my app Lazarus writes this:

  windres: warning: 14: "MAINICON": 1045: duplicate value
  windres: warning: 16: 1: 1045: duplicate value
  Project "Tst_fpc" successfully built. :)

EDIT:

Lazarus conversion tool converted .dfm -> .lfm, but has some problems with .pas file. I had to manually:

  1. add Lazarus units to uses:

    uses
    {$IFDEF FPC}
    LCLIntf, LResources,
    {$ENDIF}

  2. Conditional compile Delphi form {$R *.dfm}:

    {$IFNDEF FPC}
    {$R *.dfm}
    {$ENDIF}

  3. Add .lrs resource in initialization code:

    initialization
    {$IFDEF FPC} {$i myunit.lrs} {$ENDIF}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

城歌 2024-08-19 12:46:54

我怀疑主窗体单元(我假设它称为 utest)在其初始化部分中没有 {$I utest.lrs} 。 .lrs 是 lazarus 资源文件,由 delphi 中的 lfm (dfm) 创建。

I suspect that the mainform unit (I assume it is called utest) doesn't have a {$I utest.lrs} in its initialization section. The .lrs is the lazarus resource file, created from the lfm (dfm) in delphi.

我喜欢麦丽素 2024-08-19 12:46:54

空表单是当前项目的表单,因为您使用工具中的转换 Delphi 项目,这意味着当前项目处于活动状态。
试试这个:

  • 在项目选项上关闭当前项目
  • 在名为项目向导的小主窗口中,使用转换 Delphi 项目选项。

The empty form is the form of for the current project as you used the convert Delphi project from tools which means the current project is active.
Try this:

  • On the project option close the current project.
  • On the small main window named as project wizard, use the convert Delphi project option.
怪我鬧 2024-08-19 12:46:54

很抱歉我不能给你一个直接的答案。据我了解,资源文件有问题。在delphi中,这是*.res,我不知道它们在Lazarus中是什么样子。使用 resedit 等程序 http://www.resedit.net/ 打开资源文件。我尝试了一下,发现一个“文件夹”图标,其中有一个帖子 MANICON。我猜你有两个。在这种情况下,请删除其中一个。

I'm sorry I can't give you a straight answer. From what I understand there's a problem a problem with the resource file. In delphi that's the *.res, I don't know what they look like in Lazarus. Use a program like resedit, http://www.resedit.net/, to open the resource file. I tried it and found a "folder" Icon where there was a post MAINICON. I'm guessing you have two. In that case remove one of them.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文