Search code examples
delphidelphi-2010

Accessing common objects without prefixing


I have an app I wrote quite a while ago. It is a database app, with a lot of Ttable and TSQL components, placed on the Main Form (so it is quite messy). I am updating the app, and I want to use a datamodule. If I do that, I will have to change all of my code from Table.fieldbyName to Datmodule.FieldByName. I will have to do this type thing with a lot of different components, in a lot of different calls, (Table.Edit, Table.Post, etc) My question is... Is there a way to tell the compiler, if you don't find the object in the current form, look for it in TDatamodule? I realize I can use the 'With DataModule do' syntax, but I am hoping there is something else. Is there something I can do with NameSpace here?


Solution

  • I think the correct way to approach this would be to rename your tTable references using a search/replace tool, such as GExperts Grep Searching. Example: if you have a table called "tSales" that is now located in a datamodule named "Dm", you could just do a Grep Search for "tSales" for all files within the current project, and then replace with "Dm.tSales". The result is code that is much more readable and maintainable going forward.