Question

We are migrating Delphi 7 applications to Delphi XE. We are replacing BDE database component with ADO .In Delphi 7 application we have heavily used TwwQuery (Info Power) component. Though TwwQuery is only supported by BDE ,we have to replace TwwQuery with ADOQuery.We have around 20 + application to migrate and going to all TwwQueries and replace them manually is very time consuming. Is there any code or script which can replace all the TwwQuery to ADO Query?

Était-ce utile?

La solution 3

I am not aware of an existing script or library that will do exactly what you want but it shouldn't be too difficult to write one yourself. The basic theory would be something like this:

  • Load the contents of the DFM and PAS source files as text.
  • Scan through looking for instances of TwwQuery.
  • Replace the definition of the component with TADOQuery.
  • Update each query's properties with the ADO equivalents (I believe they are fairly similar though).
  • Save the file.

Obviously there's a bit of trial and error involved in getting it exactly right but once you have done it should work for all of your applications.

Autres conseils

GExperts has a wizard that will do this. You can right-click on any TwwQuery, and choose to replace it with a TADOQuery. There is an option to do this for all instances it finds in the application, as well as the selected one.

The SQL property should map across with no problem - obviously you then need to find some way of setting the Connection property to an ADO Connection. Or you could do this at runtime by writing some shared initialisation code which you could add to each form, that loops through the components looking for TADOQuery and setting the connection property when it finds one.

(Remember to also check your uses clause for the DBTables unit as well as removing the wwXXX entries - if you don't remove all references to it I'm pretty sure the BDE will still be needed)

reFind.exe, the Search and Replace Utility Using Perl RegEx Expressions

http://docwiki.embarcadero.com/RADStudio/XE5/en/ReFind.exe,_the_Search_and_Replace_Utility_Using_Perl_RegEx_Expressions

I think it must be:

refind *.pas *.dfm /I /W "/P:TwwQuery" /R:TADOQuery

I know this is not what you asked, but I will share my experience with you. My biggest problem with legacy code in database applications is that the main logic of it is dataset-dependent.

When I faced the very same problem you do now (I was going to replace TQuery and TwwQuery by TADOQuery) I decided to stop my dependence of TxxxQuery and become dependent on TClientDataset (CDS). I found CDS a much better dataset to work with, It has some features you won´t find in other datasets, like aggregate fields, for instance. With CDS you can load new records on demand without selecting all the rows again and you have TDatasetField as another way of handling master-detail relationships. To me it was more than enough.

Besides, the particular database access dataset stays behind TDatasetProvider component. Your main logic will be dependent on CDS only, not TADOQuery, TODACQuery or any other TxxxQuery that you may need in the future. That was the last time I had to worry about this issue. If I have to replace my datasets, it won´t affect the critical business logic anymore, only persistence logic (which I moved to another DataModule)!

So, I planed all my evolution strategy to move from TQuery and TwwQuery to TClientDataset as the first step and then replaced TQuery and TwwQuery by TADOQuery as a second step.

I didn´t use any helpers to refactor the code. It was indeed a lot of work but it had to happen only once and for all.

Nowadays I have replaced the middleware datasets (TQuery, TwwQuery, TADOQuery, etc) by a persistence service that is able to run a query and return an OleVariant with the records found. All I have to do is to assign this OleVariant to the TClientDataset.Data property and it´s done!

No more dependence of any kind of dataset in the application´s code, except for CDS!

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top