Board index » delphi » Searching for a string in a TDBMemo

Searching for a string in a TDBMemo

How can I find out if a string appears in the text of a DBMemo field??

Thanx for any help

 

Re:Searching for a string in a TDBMemo


I don't think this answer will suffice.  I'm pretty sure the example Alan
gave only works with TMemo and not TDBMemo.  You will have to
read TDbMemo via a stream and do your searching there.

procedure TForm1.Button1Click(Sender: TObject);
var
  bs : TBlobStream;
  MyStringList:        TStringList;
begin
  {Creates a blob stream read of the field name MEMOFIELD from Table1}
  bs:= TBlobStream.Create(TMemoField(Table1.fieldByName(memofield)),
bmRead);
  try
    {routes the stream to MyStringList of type TStringList}
    bs.Read(MyStringList.setText^, StrLen(MyStringList.SetText));
  finally
    {frees memory created by the blob stream}
    bs.Free;
  end;

end;

This will load the string list with your memo field.  I had to do the
opposite yesterday (write to a TDBMemo without having direct access to
the field) from a TStringList.  Took a while to figure it out because
streams are not documented very well.  

I am not sure the best logic for searching the TStringList.  One possible
solution would be getting the number of items in the TStringList,
iterating through each item testing each one via the subString command.  
Hope this helps.  E-mail me later if you have more questions.

Todd Clemetson
tclem...@alaskapermfund.com
Analyst/Programmer - Alaska Permanent Fund Corporation

Re:Searching for a string in a TDBMemo


In article <31817039.4...@flintheart.ead.auckland.ac.nz>,

Quote
kemp...@flintheart.ead.auckland.ac.nz writes...

>How can I find out if a string appears in the text of a DBMemo field??

From my scan of the help file, it looks like there are two properties which
contain the text at run-time. The first, Text, is a TCaption (defined as
String[255]), so it's not much help for longer memos. The other one, Lines,
is type TStrings, so it looks like the one to use. I suggest something like
this:

for I := 1 to Memo1.Lines.Count do
        if Pos('SubString', Memo1.Lines.Strings[I]) > 0 then
                (* String found *)

or something. HTH

                                                Alan Hohn

Re:Searching for a string in a TDBMemo


Take a look at SEARCH.PAS which comes with DELPHI 1.0. I use it to do search
and replaces against DBMemo text and it seems to work without a hitch.

Dave Hunt
Cedar Rapids, Iowa

Other Threads