Solved

Searching a Dbmemo Field in Delphi 3

Posted on 1998-12-10
7
622 Views
Last Modified: 2012-06-27
Is there a component to search for text in Dbmemo field and to check whether the memo field has no text.
Code will also do(in case of no component)
Regards
venks
0
Comment
Question by:venks
  • 4
  • 3
7 Comments
 
LVL 7

Accepted Solution

by:
ahalya earned 20 total points
ID: 1350345
Here's how i search a Memo field in my code.  The function "GetBlobAsString" returns the contents of the memo as ANSIString. Then i use the regular string searching functions.

function TSearchForm.GetBlobAsString(Blob:TBlobField): string;

var
   BlobStream: TBlobStream;
   a: array [0..8192] of Char;
   i:longint;

begin
Result:='';
BlobStream := TBlobStream.Create(Blob, bmRead);
   try
   i := BlobStream.Size;
  FillChar(a, i, #0);
   BlobStream.Read(a, i);
   finally
   BlobStream.Free;
  end;
a[i] := #0; {set the last character as null}
Result:=StrPas(a);
end;

--------------
and in my code , i do a
     FieldValue := GetBlobAsString(TMemoField(Table1.FieldByName('About')));
     FieldValue := lowercase(FieldValue);
     Match := (pos(KeyWd, FieldValue) <> 0 );
=================  
0
 
LVL 1

Author Comment

by:venks
ID: 1350346
Dear ahalya
Does your code search for mullti line text in the dbmemo.Can you geve code for a dbmemo rather than a memo field

Regards
venks

0
 
LVL 7

Expert Comment

by:ahalya
ID: 1350347
Hi Venks,

i haven't had a chance to use a "DBMemo" yet :-)  

But inside the "GetBlobAsString" you have a lot of choice, including using TStrings & pchar. i'd guess that after reading the BlobStream, you'd a lot better off by using TStrings, if you want to seperate the lines.

Ciao,
A.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:venks
ID: 1350348
Dear ahalya
I tried to use your code .But i was not sure how to use your function.Is it possible to give a complete example for callingthe Getblobasstring function for searching for data.
Regards
venks
0
 
LVL 7

Expert Comment

by:ahalya
ID: 1350349
procedure TForm1.Button1Click(Sender: TObject);

var s : String;

begin;
//search for the occurence of 'venks'  in the Field 'About'
//About is a  Memo type Field in Table 1.
//you code will have
//     DBMemo1.DataField := 'Memo'
//     DBMemo1.DataSource := DataSource1;
//     DataSource1.Dataset := Table1;


 s :=  GetBlobAsString(TMemoField(Table1.FieldByName('About')));
//you can also use
// s :=  GetBlobAsString(TMemoField(Table1.FieldByName(DBMemo1.DataFiled)));

 s := lowercase(s);
 if  (pos('venks'  FieldValue) <> 0 ) then FoundMatch
 else   Match NotFound.

end;

0
 
LVL 1

Author Comment

by:venks
ID: 1350350
Dear Ahalya
Thanks
venks
0
 
LVL 7

Expert Comment

by:ahalya
ID: 1350351
btw, Venks you gave a "B" to my answer.

To what answer would you have given an "A" ?  -just wondering.

0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

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…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

733 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