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!
> (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
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;
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!
>>>> 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.
And that last alternate solution is a good one, even when the variant is
Null.
Thanks a lot!