在 Delphi 中,如何在创建应用程序的主窗体之前分配组件的属性值?
TMS 的 FormSize 组件将 aForm 的大小和位置保存在 .ini 文件中。该文件的路径存储在组件的 SaveName 属性中。我想将 FormSize.SaveName 分配给用户的 AppData 文件夹中的文件。我可以在源代码中找到 AppData 路径。
有谁知道我在哪里(在我的代码中)将 AppData 路径分配给 FormSize.SaveName?我认为在创建 Form 之前,已创建 FormSize 组件并初始化默认的 SaveName。换句话说,FormSize 在 aForm 的 FormCreate 事件触发之前加载配置文件;在 aForm.FormCreate 期间为 FormSize.SaveName 赋值为时已晚。
谢谢,一如既往。
TMS's FormSize component saves aForm's size and position in an .ini file. This file's path is stored in the component's SaveName property. I would like to assign FormSize.SaveName to a file in the user's AppData folder. I can find the AppData path in my source code.
Does anyone know where (in my code) I assign the AppData path to FormSize.SaveName? I am thinking the FormSize component is created, and a default SaveName initialized, BEFORE aForm is created. In other words, FormSize loads the config file BEFORE aForm's FormCreate event fires; assigning a value to FormSize.SaveName during aForm.FormCreate is too late.
Thanks, as always.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
表单的调整是在
TFormSize
的Loaded
方法中完成的,而不是在更改SaveName
属性时完成的(尽管它是从之前的 DFM)。如果在设计时将属性
SavePosition
和SaveSize
设置为 false,则在运行时不会加载任何内容。在这种情况下,您可以通过调用LoadFormSettings
和SaveFormSettings
在代码中的方便位置手动加载和保存设置。The adjustment of the form is done in the
Loaded
method ofTFormSize
, not when you change theSaveName
property (although it has been read from the DFM before).If you set the properties
SavePosition
andSaveSize
to false during designtime, there will nothing be loaded at runtime. In that case you can manually load and save the settings at a convenient place in your code by callingLoadFormSettings
andSaveFormSettings
.我希望 SaveName 存储在 .dfm 文件中,因此应该在加载时将其分配给组件。
如果您想确定代码中的保存名称,它可能应该在循环的早期。我只是检查了几种可能性:
可能性 4 和 5 符合预期。 3 和 2 没有任何反应,1 引发了 AV。所以大卫的建议似乎不错。
I'd expect SaveName to be stored in the .dfm file, so it should be assigned to the component at load up.
If you want to determine the save name in code, it should probably be early in the cycle. I just checked a few possibilities:
Possibilities 4 and 5 worked as expected. 3 and 2 did nothing and 1 caused an AV. So David's suggestion seems to be fine.
我有类似的要求,需要修改模块拥有的组件属性。鉴于加载的属性已经生效,标准“Create”事件已经太晚了。
在 DFM 中的属性在调用期间分配(或缓存) 惯例,在对 Loaded 的受保护虚拟调用期间,可以覆盖 ReadState 和 Loaded 过程。
按照 确保TADOConnection 的 Connected 属性在开发过程中为 false,考虑到相关数据集的设计需求,
在签入后续构建/部署的代码之前必须将该属性设置为 false 是一件很痛苦的事情。因此,我重写了 Loaded 方法并将流属性值修改为 false。
I had a similar requirement to modify a component's property owned by a module. The standard "Create" event was too late given the loaded property was already in effect.
Properties persisted in the DFM are assigned (or cached) during the call to the protected virtual ReadState procedure. Conventionally, cached properties are activated during the protected virtual call to Loaded. Both ReadState and Loaded can be overridden.
In my case, I wanted to make sure TADOConnection's Connected property was false in the release build. During development, the component's property is normally true given design needs of dependent data sets.
It was a pain having to set the property to false prior to checking-in the code for subsequent builds/deployment. So instead, I overrode the Loaded method and hacked the streamed property value to false.