Lazarus
Home
Help
TinyPortal
Search
Login
Register
Lazarus
»
Forum
»
Programming
»
Databases
»
[SOLVED] Selecting/give focus of the current record in a TDBGrid
Free Pascal
Website
Downloads
Wiki
Documentation
Bugtracker
Mailing List
Lazarus
Website
Downloads (Laz+FPC)
Packages (OPM)
FAQ
Wiki
Documentation (RTL/FCL/LCL)
Bugtracker
CCR Bugs
GIT
Mailing List
Other languages
Foundation
Website
Useful Wiki Links
Project Roadmap
Getting the Source
Screenshots
How to use the forum
Forum Rules
About donations (wiki)
Bookstore
Computer Math and Games in Pascal
(preview)
Lazarus Handbook
Search
Advanced search
Recent
I hope FreePascal can sup...
by
Fibonacci
[
Today
at 01:37:12 am]
Remote desktop software i...
by
Boleeman
[
Today
at 12:59:14 am]
How to merge multiple cla...
by
nikel
[April 13, 2026, 11:13:18 pm]
AI assisted translation o...
by
schuler
[April 13, 2026, 10:41:29 pm]
FPC Unleashed (inline var...
by
Fibonacci
[April 13, 2026, 09:21:04 pm]
fp-h2pas: New C header tr...
by
Gustavo 'Gus' Carreno
[April 13, 2026, 06:32:22 pm]
Nezplug Library Player
by
Gigatron
[April 13, 2026, 04:15:33 pm]
Eschecs (UCI chess GUI) 5...
by
Roland57
[April 13, 2026, 04:10:12 pm]
[ANN] fpGUI Toolkit v2.0....
by
cdbc
[April 13, 2026, 03:14:21 pm]
Lazarus Bugfix Release 4....
by
dbannon
[April 13, 2026, 01:52:18 pm]
Strange happenings with T...
by
jamie
[April 13, 2026, 12:41:42 pm]
Little bit...
by
jamie
[April 13, 2026, 12:17:43 pm]
Necromancer's Dos Navigat...
by
dbannon
[April 13, 2026, 11:03:26 am]
Can't pass string to TEdi...
by
cdbc
[April 13, 2026, 10:13:44 am]
Fixed Bzip2 unpacker from...
by
domasz
[April 13, 2026, 08:09:54 am]
Ann: DeCoperators
by
Thaddy
[April 13, 2026, 07:37:29 am]
Weird error
by
xiyi0616
[April 13, 2026, 03:47:04 am]
Bad Sandwich
by
Guva
[April 12, 2026, 09:55:25 pm]
ZeosDB and sqlite3
by
dseligo
[April 12, 2026, 09:06:22 pm]
The ever re-appearing /= ...
by
Thaddy
[April 12, 2026, 08:07:09 pm]
Some Lazarus Graphics Rel...
by
Boleeman
[April 12, 2026, 03:45:30 pm]
Some Lazarus Utils N Stuf...
by
Boleeman
[April 12, 2026, 03:39:45 pm]
Ann: Deinline: a de-inlin...
by
Fred vS
[April 12, 2026, 03:17:40 pm]
BAScript - Simple scripti...
by
Ñuño_Martínez
[April 12, 2026, 01:00:21 pm]
NiceGrid component for La...
by
Alexandr R
[April 12, 2026, 11:02:54 am]
« previous
next »
Print
Pages: [
1
]
Author
Topic: [SOLVED] Selecting/give focus of the current record in a TDBGrid (Read 3263 times)
madref
Hero Member
Posts: 1116
..... A day not Laughed is a day wasted !!
[SOLVED] Selecting/give focus of the current record in a TDBGrid
«
on:
December 14, 2015, 03:21:08 pm »
I am using the following code to determine the ID of a game closest to the current date.
Code: Pascal
[Select]
[+]
[-]
cSQL
:
=
'SELECT Wed_ID, Wed_Datum, Wed_Tijd '
+
'FROM tbl_Wedstrijden '
+
'WHERE Date(Wed_Datum) > Date() '
+
'ORDER BY Wed_Datum, Wed_Tijd'
;
I am also using a
DBGrid_Wedstrijden: TDBGrid;
which contains the actual games and so on
How can i select by code the correct game?
«
Last Edit: December 14, 2015, 09:22:56 pm by madref
»
Logged
You treat a disease, you win, you lose.
You treat a person and I guarantee you, you win, no matter the outcome.
Main Platform:
--------------
Mac OS X Tahoe 26.2
Lazarus 4.99 (rev main_4_99-3149-g7867f6275c) FPC 3.3.1 x86_64-darwin-cocoa
Windows 10 Pro
Lazarus 3.99 (rev cbfd80ce39)
mangakissa
Hero Member
Posts: 1131
Re: Selecting/give focus of the current record in a TDBGrid
«
Reply #1 on:
December 14, 2015, 06:34:49 pm »
I'll try to understand what you mean. DBGrid_Wedstrijden has the output of your query. Is it not the same data, you can use Tdataset.locate() to find your record.
Logged
Lazarus 2.06 (64b) / FPC 3.0.4 / Windows 10
stucked on Delphi 10.3.1
balazsszekely
Guest
Re: Selecting/give focus of the current record in a TDBGrid
«
Reply #2 on:
December 14, 2015, 06:49:16 pm »
I assume you want to locate a specific record in the grid. Since all grids has a datasource and all datasources has a dataset, use the locate function of the dataset like this:
Code: Pascal
[Select]
[+]
[-]
SQLQuery
.
Locate
(
'Wed_ID'
,
IDToFind
,
[
]
)
;
For more complex search you can loop through the dataset(first disable the update of the visual controls):
Code: Pascal
[Select]
[+]
[-]
function
TForm1
.
LocateInGrid
(
const
ID
:
Integer
)
:
Boolean
;
var
SQLQuery
:
TSQLQuery
;
Orig_ID
:
Integer
;
begin
Result
:
=
False
;
SQLQuery
:
=
(
DBGrid_Wedstrijden
.
DataSource
.
DataSet
as TSQLQuery
)
;
Orig_ID
:
=
SQLQuery
.
FieldByName
(
'Wed_ID'
)
.
AsInteger
;
SQLQuery
.
DisableControls
;
try
SQLQuery
.
First
;
while
not
SQLQuery
.
EOF
do
begin
if
SQLQuery
.
FieldByName
(
'Wed_ID'
)
.
AsInteger
=
ID
then
//if you need add more conditions here
begin
Result
:
=
True
;
Break
;
end
;
SQLQuery
.
Next
;
end
;
if
not
Result
then
SQLQuery
.
Locate
(
'Wed_ID'
,
Orig_ID
,
[
]
)
;
finally
SQLQuery
.
EnableControls
;
end
;
end
;
«
Last Edit: December 14, 2015, 06:52:51 pm by GetMem
»
Logged
madref
Hero Member
Posts: 1116
..... A day not Laughed is a day wasted !!
Re: Selecting/give focus of the current record in a TDBGrid
«
Reply #3 on:
December 14, 2015, 09:22:41 pm »
I was on the right track but i was looking at the wrong query.
i needed to look at TQ_Wedstrijden instead of TQ_Rapport
This is my final version of what i need:
Code: Pascal
[Select]
[+]
[-]
TQ_Wedstrijden
.
Active
:
=
True
;
TQ_Wedstrijden
.
Last
;
TQ_Wedstrijden
.
First
;
GroupBox_Wedstrijden
.
Caption
:
=
Format
(
'Games (%d)'
,
[
TQ_Wedstrijden
.
RecordCount
]
)
;
// Bepaal de wedstrijd die het dichtstbij de huidige datum ligt.
cSQL
:
=
'SELECT Wed_ID, Wed_Datum, Wed_Tijd '
+
'FROM tbl_Wedstrijden '
+
'WHERE Date(Wed_Datum) > Date() '
+
'ORDER BY Wed_Datum, Wed_Tijd'
;
with
Form_Information
do
begin
TQ_Rapport
.
Active
:
=
False
;
TQ_Rapport
.
DataBase
:
=
Connect_RefereeDB
;
TQ_Rapport
.
SQL
.
Text
:
=
cSQL
;
TQ_Rapport
.
Active
:
=
True
;
TQ_Rapport
.
Last
;
TQ_Rapport
.
First
;
if
TQ_Rapport
.
RecordCount
>
0
then
begin
wi
:
=
TQ_Rapport
.
FieldByName
(
'Wed_ID'
)
.
AsInteger
;
showmessage
(
'Wed_ID = '
+
IntToStr
(
wi
)
)
;
TQ_Wedstrijden
.
Locate
(
'Wed_ID'
,
TQ_Rapport
.
FieldByName
(
'Wed_ID'
)
.
AsInteger
,
[
]
)
;
end
;
// if
end
;
// with
Logged
You treat a disease, you win, you lose.
You treat a person and I guarantee you, you win, no matter the outcome.
Main Platform:
--------------
Mac OS X Tahoe 26.2
Lazarus 4.99 (rev main_4_99-3149-g7867f6275c) FPC 3.3.1 x86_64-darwin-cocoa
Windows 10 Pro
Lazarus 3.99 (rev cbfd80ce39)
mangakissa
Hero Member
Posts: 1131
Re: [SOLVED] Selecting/give focus of the current record in a TDBGrid
«
Reply #4 on:
December 15, 2015, 09:16:00 am »
Why creating a local variabele if you don't need it?
Code:
[Select]
showmessage ('Wed_ID = ' + TQ_Rapport.FieldByName('Wed_ID').AsString);
Logged
Lazarus 2.06 (64b) / FPC 3.0.4 / Windows 10
stucked on Delphi 10.3.1
madref
Hero Member
Posts: 1116
..... A day not Laughed is a day wasted !!
Re: [SOLVED] Selecting/give focus of the current record in a TDBGrid
«
Reply #5 on:
December 15, 2015, 10:15:54 pm »
it was to check the value while in runtime.
But yes it's obsolete
Logged
You treat a disease, you win, you lose.
You treat a person and I guarantee you, you win, no matter the outcome.
Main Platform:
--------------
Mac OS X Tahoe 26.2
Lazarus 4.99 (rev main_4_99-3149-g7867f6275c) FPC 3.3.1 x86_64-darwin-cocoa
Windows 10 Pro
Lazarus 3.99 (rev cbfd80ce39)
Print
Pages: [
1
]
« previous
next »
Lazarus
»
Forum
»
Programming
»
Databases
»
[SOLVED] Selecting/give focus of the current record in a TDBGrid
TinyPortal
© 2005-2018