在数据模块上分配组件属性时发生访问冲突

发布于 2024-07-23 10:10:52 字数 1129 浏览 3 评论 0原文

我使用的是 Delphi 2009,我的应用程序包含一个数据模块,其中有一个名为“Globals”的自定义组件。

在应用程序的另一种形式中,我试图更改 Globals 组件上的已发布属性(字符串):

  dm.Globals.qhProject := _ProjectName.Text; //always gives access violation

_ProjectName 控件是 TLabeledEdit 后代。 如果框中有任何文本,我总是会遇到访问冲突。

但是,如果我手动将字符串分配给该属性,我不会得到 AV:

  dm.Globals.qhProject := 'some text'; //works

这是 qhProject 属性的声明:

FqhProject: string;    
property qhProject: string read FqhProject write FqhProject;

我根本不明白为什么这里有 AV。 我尝试过移动表单/数据模块的自动创建顺序,但我总是得到 AV。

我在这里做错了什么?

更新:

我正在使用 Billenium Effects TFormContainer 在应用程序中的不同表单之间切换。 这里涉及到的两种表单都在表单容器中。 一种形式 TdlgSummary 包含以下内容:

procedure TdlgSummary.SyncVars;
begin
    dm.Globals.qhProject := _ProjectName.Text
end;

另一种形式 TdlgFinalize 包含以下内容:

dlgSummary.SyncVars;

如果我在 dlgSummary 内部运行 SyncVars,则它可以正常工作。 如果我从 dlgFinalize 调用它,我就会得到 AV。 这似乎是问题的关键,但我无法弄清楚出了什么问题。 即使我将控制权切换到 dlgFinalize,dlgSummary 也没有被破坏,因为我可以返回到它。 有任何想法吗?

I'm on Delphi 2009, and my application contains a data module, which has a custom component named 'Globals' on it.

In another form in the application, I'm trying to change a published property (a string) on the Globals component:

  dm.Globals.qhProject := _ProjectName.Text; //always gives access violation

The _ProjectName control is a TLabeledEdit descendant. I always get an access violation here if there's any text in the box.

However, if I manually assing a string to the property, I don't get the AV:

  dm.Globals.qhProject := 'some text'; //works

Here's the declaration of the qhProject property:

FqhProject: string;    
property qhProject: string read FqhProject write FqhProject;

I can't figure out why there's an AV here at all. I've tried moving the auto create order of the forms/data module around, but I always get the AV.

What am I doing wrong here?

Update:

I'm using Billenium Effects TFormContainer to switch between different forms in the application. Both forms that are involved here are in the form container. One form, TdlgSummary, contains the following:

procedure TdlgSummary.SyncVars;
begin
    dm.Globals.qhProject := _ProjectName.Text
end;

The other form, TdlgFinalize, contains the following:

dlgSummary.SyncVars;

If I run SyncVars inside of dlgSummary, it works fine. If I call it from dlgFinalize, I get the AV. This seems to be the crux of the problem, but I can't figure out what's going wrong. Even if I switch control to dlgFinalize, dlgSummary hasn't been destroyed, because I can go back to it. Any ideas?

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

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

发布评论

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

评论(1

緦唸λ蓇 2024-07-30 10:10:52

在我看来 _ProjectName 是nil。 尝试在这一行放置一个断点并检查 _ProjectName,看看它是否提供了有效的引用。

Looks to me like _ProjectName is nil. Try putting a breakpoint at this line and examine _ProjectName, see if it gives a valid reference or not.

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