1

I am working through legacy code with over 500 forms in multiple directories. I need to find any TDataset descendent with the Tag property not set.

If I was looking for Tag being set to a particualr value, it would be in the dfm and I could search for it. In this case the Tag property will be missing from the dfm.

My best poroposal so far is to write another program that loads all the forms one at a time. In the loaded event it can check the components and the property. It is too much work to add them all manually to the project, fix the uses clause and create each one by its type. Even if I were to do this, there is no way to ensure that I did not miss a form. Also some forms have the same name as others (they are in different folders and are muutually exclusive).

Question

I would like to scan the folders for the dfm files and load the forms just from the dfm file. Is this even sensible or possible ? If so then how do I programatically load/create a form just from the dfm ?

Rohit Gupta
  • 4,022
  • 20
  • 31
  • 41
  • Why do you need to create the forms. Just parse the dfm files. This is where a scripting language comes in handy. – David Heffernan Nov 23 '15 at 21:57
  • 1
    David, I was thinking of regex and had discarded it. I hadn't though of scripting. There are still a few issues with that. 1) There many sub-classes of TDataset. I have to find all their names, which is error-prone. 2) The dfm has nested objects, I need to look for a missing Tag property in the TDataset descendant only. So, yes in theory it is possible. And if all else fails, I may have to do this. – Rohit Gupta Nov 23 '15 at 22:02
  • Is it a case is to add all forms in the application to the auto-create list and then enumerate them via Application.Components? – Abelisto Nov 23 '15 at 22:27
  • 1
    I think David Heffernan is correct. Using TClassFinder class (declared in Classes.pas) you can find all registered classes in your application, i.e. within a simple loop you can obtain a list of ALL TDataSet descendants known to your application. Using that list is relatively simple to parse all DFM files and get their tag value. – Alexandre M Nov 23 '15 at 22:31
  • I'm curious as of why you need each TDataset descendant to have its Tag property set to certain value? – SilverWarior Nov 24 '15 at 04:56
  • @SilverWarior, Its Legacy code (from the days of btrieve and tables/queries - Delphi 1) where the datasets are automatically opened in formcreate. Unless the tag is -1. We have been working away changing the tables to queries/clientdatasets and opening them on demand (and flipping the tag to -1). But before I can banish this global code, I need to ensure that we have converted every form. – Rohit Gupta Nov 24 '15 at 05:59
  • If we miss any, then the clients will get an AV when they open a form and the datasets remain closed. I need to guarantee to myself that we have sorted out each form. If I leave the code as is then any new forms may potentially have their datasets opened prematurely if the developers don't set the tag to -1. If only the original programmers had created a new property for this purpose !!!!! – Rohit Gupta Nov 24 '15 at 06:02
  • I have now written a Delphi application to scan through all dfms in all folders and then parse the dfm (root level objects only) and list all dataset descendants where the tag is not set. Found over 20, so it was well worth the few hours writing it. – Rohit Gupta Nov 24 '15 at 06:04
  • @RohitGupta Wouldn't it be better to modify the TDataset descendant class that is used in your application to change how and when database is opened. This way you could probably fix your problem at one place. – SilverWarior Nov 24 '15 at 17:24

1 Answers1

1

I would like to scan the folders for the dfm files and load the forms just from the dfm file. Is this even sensible or possible?

No this is not possible. You cannot create an instance of a form without the class that defines the form. A dfm file is not enough.

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
  • I found this post. While it doesn't quite do what I wanted. It has given me the idea that I can parse the dfm and load the component on an empty form. I only have to create the root components and I can discard panels and buttons etc. http://stackoverflow.com/questions/19989389/can-we-load-a-dfm-file-for-a-form-at-runtime – Rohit Gupta Nov 23 '15 at 22:23