Board index » cppbuilder » Getting data from TField of datatype memo

Getting data from TField of datatype memo

Hi,

I have been trying, without any success, to get the data from a TField of
DataType ftMemo using this snippet of code which is in a loop:

        else if(DataModule1->Table1->Fields[i]->DataType == ftMemo)
            {
            long size = DataModule1->Table1->Fields[i]->Size;
            if(size == 0)
                continue;
            long tmplong = tell(memfileptr);
            write(datfileptr, &tmplong, sizeof(long));
            write(datfileptr, &size, sizeof(long));
            char *buf = new char[size];
            DataModule1->Table1->Fields[i]->GetData(buf);
            write(memfileptr, buf, size);
            delete[] buf;
            }

size is always 0, but if I force it to some value, say 256, the GetData
method gives me an EDBEngineError "Operation not applicable". All I want to
do is write the contents of all the memo fields in the database table to a
file (memfileptr) as chars and record their position within that file in
datfileptr for retrieval by another program. I also note that when I display
the data in a TDBGrid the memo fields just give "(Memo)" - I presume this is
related to my problem.

Any help much appreciated.

Paul

 

Re:Getting data from TField of datatype memo


Quote
"Paul Dowd" <pauld...@seisqc.freeserve.co.uk> wrote in message

news:3ccfb7be_2@dnews...

Quote
> I have been trying, without any success, to get the data from a TField of
> DataType ftMemo using this snippet of code which is in a loop:

>         else if(DataModule1->Table1->Fields[i]->DataType == ftMemo)
>             {
>             long size = DataModule1->Table1->Fields[i]->Size;
>             if(size == 0)
>                 continue;
>             long tmplong = tell(memfileptr);
>             write(datfileptr, &tmplong, sizeof(long));
>             write(datfileptr, &size, sizeof(long));
>             char *buf = new char[size];
>             DataModule1->Table1->Fields[i]->GetData(buf);
>             write(memfileptr, buf, size);
>             delete[] buf;
>             }

> size is always 0, but if I force it to some value, say 256, the GetData
> method gives me an EDBEngineError "Operation not applicable".

Try DataSize instead of Size.  Some fieldtypes always return 0 by Size.
Have a look in the help for that.  DataSize will return the correct value.
But then you'll still receive the EDBEngineError I assume.  To workaround
that try using the AsString property of TField:

  AnsiString S=MemoField->AsString;
  write(memfileptr, S.c_str(), S.Length() );

Ralph

Re:Getting data from TField of datatype memo


Some database engines store memo fields as blobs.  Have a look at the
TBlobStream class

Gambit

Quote
"Paul Dowd" <pauld...@seisqc.freeserve.co.uk> wrote in message

news:3ccfb7be_2@dnews...

Quote
> I have been trying, without any success, to get the data from a TField
> of DataType ftMemo using this snippet of code which is in a loop:

<snip>

Re:Getting data from TField of datatype memo


This works fine - many thanks
Quote

>   AnsiString S=MemoField->AsString;
>   write(memfileptr, S.c_str(), S.Length() );

> Ralph

Other Threads