Memo2.Assign(Memo1);
When this line executes I get the error message, "Cannot assign a
TMemo to a TMemo"
WAZZUP? What do I need to do?
D5.1
Thanks.
Next up, I'll just use the text property. Thanks, John.
"John Herbster (TeamB)" wrote:
> Hi Wayne,
> If you just want to copy the contents, why not use
> Memo2.Lines.Assign(Memo1.Lines);
> {UNTESTED} Rgds, JohnH
I have not looked at the vcl-sources, but i think thats where the problem is.
just an idea
Guenther
While that has been brought up. I've never understood 'assign'. The help
is unhelpful & confusing in this matter. To take the Tmemo strings, for
example. If I wanted to 'move' the strings content of a memo to another
memo, I might think that there should be an assignment method that makes
both Tmemos reference the same Tstrings, and that I could then clear the
'source' memo, leaving the 'destination' memo with the reference to the
strings. This would mean no copying.
This is, I understand, *not* what assign does. So what does 'assign' do
that is different from a straightforward copy?
Rgds,
Martin
Kevin
"Wayne Herbert" <wher...@NOSPAMkeymaps.com> wrote in message
news:3F8F130E...@NOSPAMkeymaps.com...
Martin, This difficulty, might be because there are so many
different Assign method actions -- all with the same name.
> So what does 'assign' do that is different from a
> straightforward copy?
I look at Assign as a copy, property by property,
from one object to another object. Rgds, JohnH
Which makes no sense in the first place. If you need a way to store the
content of the memo for later use, use either a simple string or a
Tstringlist:
aStringvar := memo1.text;
or
aStringlist.Assign( memo1.lines );
Don't use controls only as data containers. If the user does not
interact with them then using a control is a waste of memory and
windows resources.
> Memo2.Assign(Memo1);
>
> When this line executes I get the error message, "Cannot assign a
> TMemo to a TMemo"
You typically get that when the two components involved have been
created in different modules (EXE and DLL, for instance), which are not
compiled with run-time packages. In this case each module has its own
version of the TMemo class. They may have the same classname, but that
is not relevant in this context. The Assign method internally uses the
Is operator to check if the passed object is of the correct class. And
Is uses the address of the class record, not the class name, to
identify a class.
--
Peter Below (TeamB)
Use the newsgroup archives :
http://www.mers.com/searchsite.html
http://www.tamaracka.com/search.htm
http://groups.google.com
http://www.prolix.be
Thank you, Peter, for pointing out to the rest of us that
we ought to pause to think before putting our fingers
to work writing these responses. Regards, JohnH
My pleasure <G>.
OK, but, say with an object propery, like Tstrings, is the property
reference only copied, or the whole object? If I have a Tmemo with some
strings & assign them to another, empty, memo, how many Tstring objects are
there? One with two identical references, or two, with different
references?
I find this assign/copy stuff wholly confusing, especially after reading the
help, so I have never use 'assign', because I don't know what's going on.
I guess I should do some testing or look at the Delphi source for Tstrings
etc. to see what 'assign' really does, but I've never got around to it.
Rgds,
Martin
> > I look at Assign as a copy, property by property,
> > from one object to another object. Rgds, JohnH
> OK. But, say with an object propery, like Tstrings,
> is the property reference only copied, ...
Martin, If you code
Memo2.Lines := Memo1.Lines;
it will do a *copy* using the fLines.Assign() method.
That is because the property declaration looks like this
property Lines: TStrings read FLines write SetLines;
and the SetLines method calls the Assign method. But
notice that the "read" calls FLines, so that if you write
MyStrings := Memo1.Lines;
where is MyStrings is of type TStrings, then you can
use the reference (really just a typed pointer) MyStrings
to refer to the contents of Memo1.Lines, even as they
are changing.
> I guess I should do some testing or look at the
> Delphi source for Tstrings etc. to see what 'assign'
> really does, but I've never got around to it.
One easy way to see what is happening is to set the
option Project | Options | Compiler | Use Debug DCUs.
Then you can step with the debugger through the code
and watch what it is doing. Rgds, JohnH