Board index » delphi » need help : storing a TStringList in a database field

need help : storing a TStringList in a database field

Hello,

Does anyone how to do the following :

If you define a table field in Interbase for instance , field content
varchar(1024) ;
you could connect this field to a DBMemo component without any problem.

However, when I want to store the lines of a TStringList component into the
same field, this
seems to be a problem.
Getting the contents into the TStringList is no problem but the other way
around gives me some problems.
I could create an AnsiString variable with the contents of each TStringList
line but when trying to store the AnsiString, I have different problems :

* if you use the .AsString conversion, the AnsiString will be cut off at 255
characters because of the limitation for a normal string.
* if I try to load the AnsiString into a PChar buffer and try to load the
buffer into the field, then I have 2 problems ;
  1) The StrLCopy function which copies n characters from a string into a
pchar var doesn't copy all characters for some reason...
 2) When I try to load the field with the pchar buffer ,for some lengths
starting somewhere between 300 and 400, it simply crashes...
FYI : The database field IS long enough so the crash can not be caused by
this.

So if somebody knows how to store a TStringList in a db-field in an easy
way, please let me know asap.

Thanx
Sven Schippers
sschipp...@glo.be

 

Re:need help : storing a TStringList in a database field


Quote
Sven Schippers wrote:
> However, when I want to store the lines of a TStringList component into the
> same field, this
> seems to be a problem.
> Getting the contents into the TStringList is no problem but the other way
> around gives me some problems.
> I could create an AnsiString variable with the contents of each TStringList
> line but when trying to store the AnsiString, I have different problems :

What about using the CommaText property?

--
Rune

Re:need help : storing a TStringList in a database field


Sven Schippers <Sschipp...@glo.be> wrote in article
<6kgtbq$5u...@trex.antw.online.be>...

Quote
> Hello,

> Does anyone how to do the following :

> If you define a table field in Interbase for instance , field content
> varchar(1024) ;
> you could connect this field to a DBMemo component without any problem.

> However, when I want to store the lines of a TStringList component into
the
> same field, this
> seems to be a problem.
> Getting the contents into the TStringList is no problem but the other way
> around gives me some problems.
> I could create an AnsiString variable with the contents of each
TStringList
> line but when trying to store the AnsiString, I have different problems :

[snip]

Simply use AMemoField.Assign.
read: AList.Assign(AMemoField);
write: AMemoField.Assign(AList);

However, it must not have any nul chars (CHR(0) or #0 or....pchar
terminator), because it will be truncated there.
If you need to store nul chars, use binary field instead.

--
-------------------------
Regards,
Robert

Remove both qwe when replying.
MailTo: robert.qwece...@eunet.qwe.si

Other Threads