Solved

How to return Selected Row information from DBGrid back to calling form when DBGrid filtered with SQL?

Posted on 2004-09-26
6
417 Views
Last Modified: 2010-04-05
Hi All,

I have a search form which allows a "Select *" type SQL statement to be performed on a table when first opened.

The intent is for the user to be able to filter the SQL statement further, and then to return the selected item back to the calling form, in order to be able to update that form, or alternatively to review details (based upon the selected item).

So far so good - I have the filter and the search form going well

The problem that I have is when I want to select that record and review it in the calling form, or use the information to update the calling form.

I've tried using RecNo, but that will only give me the correct record associated with the unfiltered search.

If I filter the search, RecNo could well be for example, the ninth record overall, but only the second record when filtered. The result returned to the form is the second record overall.

How can I get this item to perform for me, so that as per the example: the second filtered record on the DBGrid is returned as the correct ninth record overall to the calling form?

thanks in Advance
0
Comment
Question by:gunnadothat
6 Comments
 
LVL 22

Accepted Solution

by:
Ferruccio Accalai earned 130 total points
ID: 12155573
use simply a Locate....

I mean to apply a locate to the overall with the fields values from the search

For example your overall structure is

Id   Name   Age

1    Alan     10
2   Jhon      12
3   Mark      13

and the search result is 2 jhon 12

you can pass a Overall.Locate('ID;NAME;AGE',
                                             VarArrayOf([search.fieldbybyname('id').AsInteger,
                                             search.fieldbybyname('Name').AsSTring,
                                             search.fieldbybyname('AGe').AsInteger]),[]);

This will locate 2^ record on Overall
0
 
LVL 17

Assisted Solution

by:geobul
geobul earned 70 total points
ID: 12158200
Hi,

It seems that you are having two query objects - one on the main form and one on the search form. And you want to pass a selected record number (some info) to the main form in order to main form's query to go to that record.

If that is correct then perhaps you could use one query object on the main form only, use the same query in the select form and after 'filtering', selecting a record and closing the select form your main form's query will be positioned on the right record automatically (the query will remain filtered, of course, but that shouldn't be a problem because your users can always open the search form again and remove all current filters).

Regards, Geo
0
 
LVL 11

Assisted Solution

by:calinutz
calinutz earned 50 total points
ID: 12159835
On the OnKeyUp event of the Searching form place this code:

begin
If ((key=13) and (ssCTRL in Shift)) then
begin
InitialForm.Edit1.Text:=DBGrid1.Fields[0].AsString;
InitialForm.Edit2.Text:=DBGrid1.Fields[1].AsString;

Close;
end;
If key=27 then Close;
end;

// this code returns from the search form closing it and if you press CTRL+Enter on a record then It sends the value from the chosen record to the Initial Form.

// I hope this is what you needed
0
 
LVL 17

Expert Comment

by:geobul
ID: 13343285
My recommendation : split the points.
0
 

Author Comment

by:gunnadothat
ID: 13351715
Hi All,

sorry about not finalising this earlier - Uni had finished for the year and I simply forgot to complete the feedback.
Please accept my apologies.

I've split the points according to the use that I made of the answers - all were good, but I used Ferruccio68's answer as the basis for the filter, and the other responses were great to put it all into perspective.

Once again, i apologise for not doing this sooner, and thanks Dan for the prompt to complete this item - much appreciated to all.

regards

GdoT
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

919 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now