“申请” 全局变量无法识别

发布于 2024-07-08 07:24:29 字数 890 浏览 9 评论 0原文

我在 Delphi 5 中从事一个大型项目。 今天,在将应用程序的两个分支合并在一起之后,数百个单元之一,UnitMain(您猜猜主窗体的单元)停止识别应用程序全局。

这是一个相当奇怪的问题 - 我可以通过在 UnitMain 中定义 Application: TApplication 并将其设置为我们的 .dpr 项目文件中的应用程序来编译程序,但这会导致访问冲突,这并不是什么大问题。令人惊讶的是应用程序是特别的。

我希望有人以前遇到过同样的问题,或者对 Delphi VCL 的内部工作原理有足够的了解来帮助我解决这个问题。

unit UnitMain;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Menus, ComCtrls, StdCtrls, cxButtons, ExtCtrls, IniFiles, ShellAPI,
  LMDControl, LMDBaseControl, LMDBaseGraphicControl, LMDGraphicControl,
  LMDScrollText, cxControls, cxContainer, cxListBox, Psock, NMFtp, db, DBTables,
  FileCtrl, Configs, cxHint, DSetFunc, OleCtrls, DsInformation,
  InterAppComm, ActnList, ADODB, OleServer, CRAXDRT_TLB;

确切的错误是编译器无法识别该单元中的Application。 例如,对于 Application.ProcessMessages; 调用时,错误是“需要对象或类类型”。 其他单位都没有这个问题。

I work on a large project in Delphi 5.
Today, after merging two branches of the app together, one of the hundreds of units, UnitMain (the main form's unit, would you guess) stopped recognizing the Application global.

This is a rather bizarre problem - I could get the program to compile by defining Application: TApplication in UnitMain, and setting that to the Application from our .dpr project file, but that leads to an access violation, which isn't much of a surprise with Application being the special thing it is.

I'm hoping someone has faced the same problem before, or knows enough of Delphi VCL's inner workings to help me out here.

unit UnitMain;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Menus, ComCtrls, StdCtrls, cxButtons, ExtCtrls, IniFiles, ShellAPI,
  LMDControl, LMDBaseControl, LMDBaseGraphicControl, LMDGraphicControl,
  LMDScrollText, cxControls, cxContainer, cxListBox, Psock, NMFtp, db, DBTables,
  FileCtrl, Configs, cxHint, DSetFunc, OleCtrls, DsInformation,
  InterAppComm, ActnList, ADODB, OleServer, CRAXDRT_TLB;

The exact error is that the compiler does not recognize Application in this unit.
For example, for a Application.ProcessMessages; call, the error is "Object or class type required".
None of the other units has this problem.

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

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

发布评论

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

评论(3

梦旅人picnic 2024-07-15 07:24:29

我认为您很可能在范围内有两个名为“应用程序”的符号,而表单单元中的符号不​​是活动符号。 确保使用列表中的“表单”单元位于包含“应用程序”符号的任何先前单元之后。

但是,您需要提供更多信息。 具体的错误信息等等。

I think it is most likely that you have two symbols called "Application" in scope, and the one from the Forms unit isn't the active one. Make sure the Forms unit in the uses list comes after any prior unit that contains a symbol called Application.

But, you need to provide more information. The exact error messages, etc.

怀念你的温柔 2024-07-15 07:24:29

我很高兴看到现在一切正常,但我会补充说解决此类问题的另一种方法,特别是如果您不想重新排列您的使用子句,是将单元名称作为您想要使用的任何内容的前缀,例如。

Forms.Application.ProcessMessages;

I'm pleased to see everythings working now, but I'll add that another way to solve such problems, especially if you don't want to rearrange your uses clauses is to prefix the unit name to whatever you want to use, eg.

Forms.Application.ProcessMessages;
¢好甜 2024-07-15 07:24:29

文件顶部的 use 子句中包含哪些单位? 申请来自“表格”单元。

例如。

unit MyUnit;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms;

What units are in the uses clause at the top of the file? Application comes from the "Forms" unit.

eg.

unit MyUnit;

interface

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