Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delphi issue with sharing Image Lists across forms

Tags:

delphi

I've been sharing image lists across multiple forms in Delphi for years now. I have a TImageList on the main form of my app and then I have other forms that have components where I set the Images property to the image list from the main form (e.g. MyMainForm.MyImageList) at design time.

The problem I'm having is that randomly the Images property gets cleared on those forms that reference the image list on the main form.

This seemed to have only start recently, but I haven't been able to pinpoint the exact cause yet. I can't seem to find a way to reproduce the issue at will; it just seems to happen randomly. I did notice it happens right when a form is opened.

One thing that I did change recently in Delphi is I enabled the Autosave Project desktop and symbols feature. So now when I open this project it always remembers what forms were open. So because this issue happens when a form is opened, and because it now reopens all forms that were opened the last time the project was opened, it happens more often.

We have a few developers working on this project, and we are using SVN for version control. One issue that enabling the Autosave Project desktop and symbols feature has led to is that when we do an SNV update on the project, the symbol file can become invalid (because we don't have the symbol file under version control). This just leads to an error message from Delphi, but other than that it seems harmless. We just recompile the project and it fixes the symbol file.

Btw, I'm using Delphi 7.

If you have questions or want clarifications, leave a comment, and I'll update the question.

like image 545
Liron Yahdav Avatar asked Dec 18 '08 03:12

Liron Yahdav


3 Answers

I ran into the same problem many years ago. Ever since, I've had the habit of putting image lists that are shared by several forms onto a TDataModule. Then Delphi doesn't lose the link. Putting non-visual components on data modules also reduces design time clutter on your forms. At runtime, the TDataModule is instantiated before the main form.

like image 98
Jan Goyvaerts Avatar answered Oct 27 '22 23:10

Jan Goyvaerts


Ah - and the "AutoSave Project desktop" feature will sometimes open files (and, hence, forms) in "reverse" order - exacerbating the IDE-doesn't-know-about-MyMainForm "feature".

like image 41
moobaa Avatar answered Oct 28 '22 00:10

moobaa


I put kind of shared things to Datamodules instead of forms. Try with this way.

like image 27
Serguzest Avatar answered Oct 28 '22 00:10

Serguzest