Solved

Searching a Dbmemo Field in Delphi 3

Posted on 1998-12-10
7
609 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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

705 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

20 Experts available now in Live!

Get 1:1 Help Now