Searching for a string in a TDBMemo

"Todd A. Clemetson" <> writes:

> 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
> Analyst/Programmer - Alaska Permanent Fund Corporation

I've had a similar problem.
Here's two other ways to access the data in a TDBMemo:
use a memo or .asString.

(Two cautionary notes:

 1. Set Memo1.wordwrap:=false; - otherwise the lines returned
    correspond in length to the memo's display width
 2. Borland Tech Support e-mailed me a response to one of my previous
    postings that using .AsString in this situation was not supported:

">From:  Steve Koterski[]
 >Sent:  Saturday, May 04, 1996 4:09 AM
 >To:  Paul Motyer
 >Subject:  Re: Accessing a Paradox Memo field from a DLL
 >The AsString property does not apply to memo fields (via the TMemoField
 >component), whether you are using it from an EXE or a DLL. There is no
 >equivalent -- such as an AsMemo property -- because memo and BLOB fields
 >represent too complex a data type. The As* properties are designed for use
 >with data types with which the assignment, or gets, operator (:=) can be
 >used. ..."

 -despite this, however, it works! - at least in the current version of D2
 (my memos are one long string, there is no 2nd line)

unit Unit1;


  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, DB, DBTables;

  TForm1 = class(TForm)
    Button1: TButton;
    DataSource1: TDataSource;
    Table1: TTable;
    Memo1: TMemo;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    procedure Button1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    { Private declarations }
    { Public declarations }

  Form1: TForm1;


{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
label1.caption:= table1.fieldbyname('Description').asString;
label2.caption:= memo1.lines[0];
label3.caption:= memo1.lines[1];
label4.caption:= memo1.lines[2];
label5.caption:= memo1.lines[3];
label6.caption:= inttostr(length(table1.fieldbyname('Description').asString));

procedure TForm1.FormCreate(Sender: TObject);


Paul,           (Mon, 6 May 96, 14:45 EST)
SoftStuff, Croydon, Victoria, Australia, 3136