Jump to content
Roger Cigol

FireDAC - how to change an FDQuery field type?

Recommended Posts

I have a Win64 C++ Builder VCL FireDAC application. I have a TFDQuery that is used as the source for a TBindSourceDB component which in turn is used for livebindings for conveniently displaying the query results on a string grid.

With the change from RAD Studio 11 to RAD Studio 12 (patch 1) came the introduction of better support for fields of TimeStamp with offset (timezone) types. With RAD Studio 11 it seems that these were just treated as TimeStamp

fields (ie the time zone offset was ignored). Code that worked in RAD Studio 11 stopped working in RAD Studio 12 (patch 1) and I traced the problem to the fact that one of the field definitions for this particular TFDQuery now needed

to be changed from type TSQLTimeStamp (which worked in 11.) to TSQLTimeStampOffset (which works in 12-patch 1). The underlying type in the postgreSQL database for this field has always been "time stamp with time zone".

I have this all understood and it is all now working following this change of type.

MY QUESTION

Is there a convenient way to change the TYPE of a field definition through the IDE? I couldn't find a way to do what you would think should be a simple task. In the end I "cut" the query component to the clip board, pasted it into a

text editor, changed the type as described above, copied the text editor contents to the clip board and then pasted it back into the VCL data module. Not actually too difficult but hardly what you would expect to have to do in a

RAD Studio IDE! I suspect I am missing a trick, hence this appeal for advice....

Attachments: file "Structure.jpg" shows the field (after my change of data type) selected in the structure pane. In the properties pane there are lots of properties, but not (or I couldn't find it!) the field type.

"NewField.jpg" shows the "wiard" form that appears if you add a new field to the field definition - here there is a drop down box in which all the possible field types appear and you can pick the one you need.

But I can't find a way of getting this box up again for an existing field...

 

(Not sure if this should have been posted under category: IDE, VCL or Database - so I went for "Database").

Structure.JPG

NewField.JPG

Share this post


Link to post

I hope that this is going to work the same for C++ (I am doing it in Delphi):

1.) Open the file, select View as Text (Alt + F12)

2.) Do a search and replace

3.) go back to View as Form (alt + F12)

4,) save the file.

 

During the saving process the IDE should ask to replace the definition. This the Delphi way

 

Plan b. do the search & replace using refind.exe - https://docwiki.embarcadero.com/RADStudio/Alexandria/en/ReFind.exe,_the_Search_and_Replace_Utility_Using_Perl_RegEx_Expressions in case you have multiple forms.

Edited by Lajos Juhász
refind.exe
  • Like 1
  • Thanks 1

Share this post


Link to post

Hi @Lajos Juhász

Thanks for this. Usually editing techniques apply equally to Delphi or C+. I have the datamodule on the screen. But under my View menu I do not have a "View as text" option (is it somewhere else?). However alt+F12 does indeed change the form view to the text equivalent. Here I can manually edit the field (or anything else!). And alt+F12 toggles it back afterwards. I never knew this short cut (after all these years.....). So this saves me manually cutting and pasting to a different text editor. This may be useful to me in the future.

It does still strike me as not being a RAD Studio IDE elegant way to edit a property. I wonder why the field type does not appear in the "properties" pane? I can visualise that there could be a good reason for this but if so it would be much better if a right click on the field in the structure display also gave me an option to bring up a window the same as the "new" field window - where I could then adjust the type. 

May be I'll put in a feature request when the quality portal comes back from its "holiday"......

Share this post


Link to post

In design view, right click your query and select "Fields Editor...".

If the field that has been changed is listed here, delete it and click "Add All Fields" or "Add Field...".

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×