📄 sql.htm
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<TITLE>UDDF - SQL/TQUERY</TITLE>
<META NAME="Description" CONTENT="SQL and Tquery section of the Delphi Developers FAQ" >
<META NAME="KeyWords" CONTENT="" >
</HEAD>
<BODY LINK="#0000ff" VLINK="#800080" BGCOLOR="#ffffff">
<CENTER>
<IMG SRC="../images/uddf.jpg"> </CENTER>
<P><HR SIZE=6 color="#00FF00"></P>
<FONT FACE="Arial Black" SIZE=7 COLOR="#ff0000"><P ALIGN="CENTER">SQL and TQuery</FONT> </P>
<P><H1><A NAME="sql0">Finding a record in a TQuery<IMG SRC="../images/new.gif" WIDTH=28 HEIGHT=11 BORDER=0 ALT=" [NEW]"></P></A></H1>
<PRE>How do you 'Find' a record in a TQuery?</PRE>
<I>[David G. Edwards, dedwards@athensnet.com]</I><P>
I use something like this, but it could use some exception handling. When
the user presses the "Find" button, it's OnClick event handler calls
SearchName. <p>
<HR><PRE>
Declare FindSearch : Boolean and initialize it to true.</PRE><HR>
<P>
<HR><PRE>
function LookForString(target, source : string) : boolean;
{ if Ignoring case, convert source and target to all upper case before
calling pos }
begin
LookForString:= pos(target, source);
end;
procedure SearchName(searchtype : string; stringtofind : string);
var
OldCursor : TCursor;
CurrentPos : TBookmark;
found: boolean;
begin
if Form1.Query1.State=dsEdit then Form1.Query1.Post;
if StringToFind='' then exit;
OldCursor:= Screen.Cursor;
Screen.Cursor:= crHourGlass;
with Form1 do
begin
CurrentPos:= Query1.GetBookmark;
Query1.DisableControls;
found:= false;
if searchtype <> 'prev' then { first or next }
begin
if searchtype = 'first' then Query1.First
else if not Query1.EOF then Query1.Next;
while (not Query1.EOF) and (not found) do
begin
if LookForString(StringToFind, MemberName)<>0 then found:= true;
if not found then Query1.Next;
end;
end
else
begin { prev }
if not Query1.BOF then Query1.Prior;
while (not Query1.BOF) and (not found) do
begin
if LookForString(StringToFind, MemberName)<>0 then
found:= true;
if not found then Query1.Prior;
end;
end;
Screen.Cursor:= OldCursor;
if found then
begin
FindSearch:= false;
ChangeFindCaption;
UpdateStatusLabel;
end
else
begin
MessageDlg('No more matching members found.', mtInformation,
[mbOK], 0);
Query1.GotoBookmark(CurrentPos);
end;
Query1.EnableControls;
Query1.FreeBookmark(CurrentPos);
end; { of with Form1 }
end;
procedure TForm1.FindButtonClick(Sender: TObject);
begin
if FindSearch then SearchName('first', Page0Edit.Text)
else SearchName('next', Page0Edit.Text);
end;</PRE><HR>
<HR SIZE="6" color="#00FF00">
<P><A HREF="mailto:rdb@ktibv.nl">
<FONT SIZE=2>Please email me</FONT></A><FONT SIZE=2> and tell me if you liked this page.<BR>
<SCRIPT LANGUAGE="JavaScript"><!--
document.write("Last modified " + document.lastModified);
// --></SCRIPT></FONT>
<P ALIGN="CENTER"><CENTER><TABLE CELLSPACING=0 BORDER=0>
<TR><TD VALIGN="MIDDLE">
<P><FONT SIZE=2>This page has been created with </FONT></TD>
<TD VALIGN="MIDDLE">
<P><A HREF="http://www.dexnet.com./homesite.html"><IMG SRC="../images/hs25ani.gif" WIDTH=88 HEIGHT=31 BORDER=0 ALT="HomeSite 2.5b"></A></TD>
</TR>
</TABLE>
</CENTER></P>
<P> </P>
</BODY>
</HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -