Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to use a function to search text in part of a field of any dataset Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
A function to search text in part of a field of any dataset 27-May-03
Category
VCL-General
Language
Delphi 3.x
Views
89
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Ernesto De Spirito

A function to search text in part of a field of any dataset

Answer:

The following function searches for text in any part of a field of any dataset (it 
can be for example a TTable, TQuery, TADOTable, TADOQuery, TIBTable, TIBQuery, 
etc.) 

1   type
2     TLocateStrOption = (loCaseSensitive, loContinue);
3     TLocateStrOptions = set of TLocateStrOption;
4   
5   function LocateStr(Dataset: TDataset; Field: TField; Str: string;
6     LocateOptions: TLocateStrOptions): boolean;
7   // Searches text in any part of a dataset field. The search can be
8   // case sensitive (option loCaseSensitive) and can start from the
9   // beginning or from the current record (option loContinue).
10  //
11  // Returns True if the string was found (the dataset is positioned
12  // in that record) and False otherwise (the dataset is left in EOF)
13  var
14    ControlsDisabled: boolean;
15  begin
16    ControlsDisabled := Dataset.ControlsDisabled;
17    if not ControlsDisabled then
18      Dataset.DisableControls;
19    try
20      if loContinue in LocateOptions then
21      begin
22        if not Dataset.Eof then
23          Dataset.Next;
24      end
25      else
26        Dataset.First; // Start from the beginning
27      if not (loCaseSensitive in LocateOptions) then
28        Str := UpperCase(Str);
29      while not Dataset.Eof do
30      begin
31        if loCaseSensitive in LocateOptions then
32        begin
33          if Pos(Str, Field.AsString) <> 0 then
34            break;
35        end
36        else
37        begin
38          if Pos(Str, UpperCase(Field.AsString)) <> 0 then
39            break;
40        end;
41        Dataset.Next;
42      end;
43      Result := Dataset.Eof;
44    finally
45      if not ControlsDisabled then
46        Dataset.EnableControls;
47    end;
48  end;



Copyright (c) 2001 Ernesto De Spirito
Visit: http://www.latiumsoftware.com/delphi-newsletter.php

			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC