Searching for a string in a TDBMemo

"Todd A. Clemetson" <tclem...@alaskapermfund.com> writes:

Quote
> 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

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[SMTP:koter...@borland.com]
 >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;

interface

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

type
  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
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
begin
Table1.next;
memo1.lines.assign(TMemoField(table1.fieldbyname('Description')));
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));
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
memo1.wordwrap:=false;
table1.first;
end;

end.

Paul,           (Mon, 6 May 96, 14:45 EST)
SoftStuff, Croydon, Victoria, Australia, 3136
pa...@linuxserver.pccity.com.au