Watch, Follow, &
Connect with Us

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


Welcome, Guest
Guest Settings
Help

Thread: FireDac C++ and select row



Permlink Replies: 3 - Last Post: Nov 23, 2015 8:09 AM Last Post By: quinn wildman
Vaclav Smidl

Posts: 27
Registered: 1/23/11
FireDac C++ and select row
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 15, 2015 2:18 AM
Hello,
Iam using firedac components to access my Postre database. Iam able to put TFDConnection, TFDQuery and TDataSource into my form and show database`s table in DBGrind. I would like to click on row in dbgrid and get data form all columns. In dbgrid I presenting not all columns from database. So it could be good to get this information form TFDQuery (or TDataSource) and not form dbgrid.
How to get row index from row click into dbgrid?
How to get data (for each column) from TFDQuery(or TDataSource) for this row index?
quinn wildman

Posts: 856
Registered: 12/2/99
Re: FireDac C++ and select row
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 20, 2015 8:49 AM   in response to: Vaclav Smidl in response to: Vaclav Smidl
Vaclav Smidl wrote:
Hello,
Iam using firedac components to access my Postre database. Iam able to put TFDConnection, TFDQuery and TDataSource into my form and show database`s table in DBGrind. I would like to click on row in dbgrid and get data form all columns. In dbgrid I presenting not all columns from database. So it could be good to get this information form TFDQuery (or TDataSource) and not form dbgrid.
How to get row index from row click into dbgrid?
How to get data (for each column) from TFDQuery(or TDataSource) for this row index?

How do you want to get the data? Into a variable, into a report, into
something that displays on the screen? In general, you just needs to
access the fields array in the TFDQuery. It will be updated to be on the
correct row as you navigate the grid.

Example1:

MyFDQuery->FieldByName("My field")->AsString

Example2:

MyFDQuery->Fields->Fields[0]->AsStrin

You could also have persistent fields in your TFDQuery and access those.

Assuming this is a VCL application, if you just want to display other
fields on the screen, just use a TDBEdit. No code required.
Vaclav Smidl

Posts: 27
Registered: 1/23/11
Re: FireDac C++ and select row
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 22, 2015 1:13 PM   in response to: quinn wildman in response to: quinn wildman
quinn wildman wrote:
How do you want to get the data? Into a variable, into a report, into
something that displays on the screen? In general, you just needs to
access the fields array in the TFDQuery. It will be updated to be on the
correct row as you navigate the grid.

Example1:

MyFDQuery->FieldByName("My field")->AsString

Example2:

MyFDQuery->Fields->Fields[0]->AsStrin

You could also have persistent fields in your TFDQuery and access those.

Assuming this is a VCL application, if you just want to display other
fields on the screen, just use a TDBEdit. No code required.

Your example works.
I use Grid1CellClick function for grid click event. In this function I get all relevant columns (MyFDQuery->FieldByName("My field")->AsString) and sent them to next processing. Good for me.
Is whole table loaded into FDQuery component? If I want show in DBGrid 1000000 rows all that rows will be loaded into memory or there is some mechanism which can load only part of database which is actually viewing?
And what about inserting? How can I Insert row into database table from code and how do the dbgrid refresh?
quinn wildman

Posts: 856
Registered: 12/2/99
Re: FireDac C++ and select row
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 23, 2015 8:09 AM   in response to: Vaclav Smidl in response to: Vaclav Smidl
Vaclav Smidl wrote:
Your example works.
I use Grid1CellClick function for grid click event. In this function I get all relevant columns (MyFDQuery->FieldByName("My field")->AsString) and sent them to next processing. Good for me.
Is whole table loaded into FDQuery component? If I want show in DBGrid 1000000 rows all that rows will be loaded into memory or there is some mechanism which can load only part of database which is actually viewing?
And what about inserting? How can I Insert row into database table from code and how do the dbgrid refresh?

All the rows you have fetched are in memory. If want all rows to be
fetched in memory execute MyFDQuery->Last. This said, I doubt you want
1,000,000 rows in memory. What's the point? If did a Google search that
resulted in 1,000,000 results, would you want them all displayed on the
screen?

Having 1,000,000 in memory will use a lot of memory as well. I would
suggest a well laid out design limits the number of records to the
number a human can process. In most cases I suggest that is no more than
a a few hundred.

To insert a row call TFDQuery->Insert. Your inserts will inserted where
the row cursor currently resides.
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02