Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


ID: 18983, Fix for component reference bug across units

by Peter Laman Email: Anonymous


FIX: If a component has references to components in another unit, the references are sometimes lost when opening the unit.
Download Details
FTP  download also available
CDN Login Required to Download. (You will be redirected to the login page if you click on the Download Link)
To download this, you must have registered:
A free membership

For Delphi, Version 6.0  to 6.0 132 downloads
Copyright: Open Source or other


Size: 851,350 bytes
Updated on Thu, 17 Oct 2002 02:06:41 GMT
Originally uploaded on Thu, 17 Oct 2002 02:02:27 GMT
SHA1 Hash: EC05B4B22C147A06B8DAE4EDBE723D6B2114660B
MD5 Hash: 577189DC671564448ED9607F958029A6

    Explore the files in this upload

Description
Important: Using the software described below implies your agreement with the terms of use included in the GlobRef.Doc file.

Problem
In a Delphi form or data module, a component may refer to another component. For example, the DataSet property of the TDataSource class contains a reference to a query or a table component.
The referred component does not necessarily have to exist on the same form or data module. For example, a TQuery may reside on a data module, while the TDataSource is on a form, connecting Data Aware Controls to the query. Normally, when the form is opened in the Delphi IDE, the IDE would open the data module as well, in order to be able to restore the reference.

However, due to an apparent bug in Delphi 5 and 6, this does not always work. Sometimes the IDE fails to open the referenced unit, leaving the referencing property blank. And, worst of all, this happens without any error message. So, if it’s not your lucky day, opening the form without having opened the data module first will break the link between your Data Source and the query. If you would save the unit again, the property is lost permanently.

Now, if you have a large program – and since you’re a professional developer, that’s probably the case – this will happen sooner or later. At first, it caused me not to use this feature at all, because I don’t want to run the risk of introducing bugs only by opening and closing files in the IDE.
Solution
But later I decided, to create the required logic myself. The result is the TGlobalReferenceProtector (GRP) component. The principle is simple. The GRP is placed on the form that contains the references. When the form is saved, GRP will scan all components on the form and find all the existing component references to other forms or data modules. Information on these references is stored inside the DFM.
When the form is loaded again, the GRP component checks if all referenced units have already been opened by the IDE. If they are, it does nothing, so it won’t bother you with any messages if the IDE did a good job. If some units have not been opened, GRP issues asks for a confirmation, opens the units and restores all references that failed to be restored.

   Latest Comments  View All Add New

Move mouse over comment to see the full text

Server Response from: ETNACDC03