Solved

Searching a Dbmemo Field in Delphi 3

Posted on 1998-12-10
7
613 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This is a video describing the growing solar energy use in Utah. This is a topic that greatly interests me and so I decided to produce a video about it.

930 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

12 Experts available now in Live!

Get 1:1 Help Now