Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[Delphi 6] How can i copy a DbMemo to a Memo?

372 views
Skip to first unread message

Broc_Ex_Co

unread,
Jun 17, 2008, 5:49:12 AM6/17/08
to
(Sorry for my poor english.)

I have to manipulate a DbMemo in a file and copy it in a Memo.

Table.FieldByName('Memo1').Value is a Variant.

How is it possible to copy it in a Memo?

Thanx!


Maarten Wiltink

unread,
Jun 17, 2008, 7:33:44 AM6/17/08
to
"Broc_Ex_Co" <broc...@wanadoo.fr> wrote in message
news:48578894$0$895$ba4a...@news.orange.fr...

> (Sorry for my poor english.)

Pardon my French, too.


> I have to manipulate a DbMemo in a file and copy it in a Memo.
>
> Table.FieldByName('Memo1').Value is a Variant.
>
> How is it possible to copy it in a Memo?

Assign it to something that expects a string. The value is most
likely 'really' a string and even if it isn't, the runtime will
do its best to convert it to one.

The Memo's Lines property is a TStrings object, and its Text property
is a string. Assign your variant to that.

Groetjes,
Maarten Wiltink


BRoberts

unread,
Jun 17, 2008, 7:00:40 PM6/17/08
to

"Broc_Ex_Co" <broc...@wanadoo.fr> wrote in message
news:48578894$0$895$ba4a...@news.orange.fr...

Many different ways. Two easy ones:

if Not VarIsNull (aTable ['Memo1']) // it will be Null if it's blank or
empty, i.e. ''
then aMemo.Lines.Text := aTable ['Memo1']
else aMemo.Clear;

or

aMemo.Lines.Text := aTable.FieldByName ('Mem1').AsString;

Broc_Ex_Co

unread,
Jun 19, 2008, 3:00:49 AM6/19/08
to

"BRoberts" <berdon...@caneris.ca> a écrit dans le message de news:
db8eb$485841a1$cef89f20$88...@TEKSAVVY.COM-Free...

Thanx a lot!
I tried your way, but i have an error : Access violation at adress ......
.....

Do you have another suggestion of amelioration?


BRoberts

unread,
Jun 19, 2008, 8:42:05 PM6/19/08
to

"Broc_Ex_Co" <broc...@wanadoo.fr> wrote in message
news:485a0420$0$834$ba4a...@news.orange.fr...

I gave you two methods, which caused and access violation? If it was both,
then I would suspect your code. I did test the methods before posting them.

Broc_Ex_Co

unread,
Jun 20, 2008, 11:02:44 AM6/20/08
to

"BRoberts" <berdon...@caneris.ca> a écrit dans le message de news:
cfd4e$485afa00$45c484bf$32...@TEKSAVVY.COM-Free...

Sorry! i use your first method ... but it was with table using the component
Tdbf (from sourceforge).
I'll try with a component Ttable BDE during the week-end!


BRoberts

unread,
Jun 20, 2008, 5:24:45 PM6/20/08
to

"Broc_Ex_Co" <broc...@wanadoo.fr> wrote in message
news:485bc692$0$866$ba4a...@news.orange.fr...

>>>> if Not VarIsNull (aTable ['Memo1']) // it will be Null if it's blank
>>>> or empty, i.e. ''
>>>> then aMemo.Lines.Text := aTable ['Memo1']
>>>> else aMemo.Clear;
>>>>
>>>> or
>>>>
>>>> aMemo.Lines.Text := aTable.FieldByName ('Mem1').AsString;
>>>
>>> Thanx a lot!
>>> I tried your way, but i have an error : Access violation at adress
>>> ...... .....
>>>
>>> Do you have another suggestion of amelioration?
>>>
>>>
>>
>> I gave you two methods, which caused and access violation? If it was
>> both, then I would suspect your code. I did test the methods before
>> posting them.
>
> Sorry! i use your first method ... but it was with table using the
> component Tdbf (from sourceforge).
> I'll try with a component Ttable BDE during the week-end!
>

Both methods should work with any tDataSet descendant. An alternate might be
something like

aMemo.Lines.Text := VarToStr (aTable.FieldByName ('Memo1').Value)

I can't recall how VarToStr reacts to a Null variant, it should return ''.
If it raises an Invalid Variant Conversion exception then one would have to
test for Null before the line above.

Broc_Ex_Co

unread,
Jul 10, 2008, 12:53:44 PM7/10/08
to

"BRoberts" <berdon...@caneris.ca> a écrit dans le message de news:
7b66$485c1d3d$45c484bf$21...@TEKSAVVY.COM-Free...

And that last alternate solution is a good one, even when the variant is
Null.

Thanks a lot!


0 new messages