Board index » delphi » Retreiving text from TMemoField

Retreiving text from TMemoField

Hi every delphi programmers,

My configuration :

-Windows NT3.51
-Delphi 1.02 C/S
-Oracle 7
-SQL*Net TCP/IP Client 1.1.6.9

My problem is that I'm unable to retrieve the value
of a TMemoField.  The field have 2000 caracters and
the only way I have to get the data(I think) is using
the GetData method.  The field contains the list of
allergy of a patient.  Each are separate with a comma
and I want to display each allergy on a separate line
of a TMemo.

Here's what I tried :

  Size := q_identi.FieldByName('allergie').Datasize;
  Try
   GetMem(ptr,Size);
   if Field1.GetData(ptr) then
     showmessage(Char(ptr^));
  Finally
   FreeMem(ptr,size);
  end;

Many thanks to all of yours that will help me.

Richard.

 

Re:Retreiving text from TMemoField


Dear Richard,

why not use:
unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    q_ident: TTable;
    Memo1: TMemo;
    Memo2: TMemo;
    procedure ShowAllergies;
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.ShowAllergies;
var     s:string;
        i:integer;
begin
memo2.clear; {allergy display}
if TMemoField(q_ident.fieldbyname('allergie')).isNull then exit;

memo1.lines.assign(TMemoField(q_ident.fieldbyname('allergie')));

{then, you'll have to go through each line,
find the commas and split them onto separate lines:}

For i:=0 to memo1.lines.count-1 do
        begin
        s:=memo1.lines[i];
        while pos(',',s)>0 do
              begin memo2.lines.add(copy(s,1,pos(',',s)-1));
              delete(s,1,pos(',',s));
              end;
        end;
end;
end.
--
Paul,           (Sat, 15 June 96, 00:45 EST)
SoftStuff, Croydon, Victoria, Australia, 3136
pa...@linuxserver.pccity.com.au
-------------------------------------

Quote
On Thursday, 13 June 1996, Richard Pineault wrote...
> Hi every delphi programmers,

> My configuration :

> -Windows NT3.51
> -Delphi 1.02 C/S
> -Oracle 7
> -SQL*Net TCP/IP Client 1.1.6.9

> My problem is that I'm unable to retrieve the value
> of a TMemoField.  The field have 2000 caracters and
> the only way I have to get the data(I think) is using
> the GetData method.  The field contains the list of
> allergy of a patient.  Each are separate with a comma
> and I want to display each allergy on a separate line
> of a TMemo.

> Here's what I tried :

>   Size := q_identi.FieldByName('allergie').Datasize;
>   Try
>    GetMem(ptr,Size);
>    if Field1.GetData(ptr) then
>      showmessage(Char(ptr^));
>   Finally
>    FreeMem(ptr,size);
>   end;

> Many thanks to all of yours that will help me.

> Richard.

Re:Retreiving text from TMemoField


Quote
Richard Pineault <r...@logibec.com> wrote:
>My problem is that I'm unable to retrieve the value
>of a TMemoField.  The field have 2000 caracters and
>the only way I have to get the data(I think) is using
>the GetData method.  The field contains the list of
>allergy of a patient.  Each are separate with a comma
>and I want to display each allergy on a separate line
>of a TMemo.

TMemo will start the following text on a new line when it has a CR/LF
so you have to have some way of converting the comma to a CR/LF.

You might try streaming the TMemoField into a PChar, then splitting up
the PChar data (at every comma) into a TStringList, then assigning the
TStringList to the TMemo.

Assigning to the TStringList directly, eg
TStringList.Assign(TMemoField) works, but, if the chunk of text
between CRLFs is greater than 255 chars, then only 255 chars are
assigned.

==
Bob Small

Re:Retreiving text from TMemoField


Memo:=Tmemo.Create(Application.mainform);
with memo do begin
        visible:=false;
        Parent:=Application.mainform;
        Align:=AlClient;
        Memo.lines.assign(Table1.Fieldbyname(MyMemoField));
        {Do something}
        free;
end;

There othees ways with TStringList and TStrings....

Other Threads