Board index » cppbuilder » Edit1->Text assigment in a sub function

Edit1->Text assigment in a sub function


2005-10-12 08:26:28 PM
cppbuilder44
Hi
I've made som code, I dont understand why is not working.
void r(AnsiString &pas)
{
pas.sprintf("%07ld",56);
}
void p(AnsiString *pas)
{
pas->sprintf("%07ld",12);
}
void __fastcall TForm1::Button1Click(TObject *Sender)
{
AnsiString s;
r(s);
Edit1->Text = s; // Edit1 change its value!
r((Edit2->Text)); // this do not work?? Edit2 do NOT change value?
p(&s);
Edit3->Text = s; // Edit3 changes its value
p(&(Edit4->Text)); // this do not work?? Edit4 do NOT change value?
}
Why cant I use the Edit->Text directly in my function call?, but have to use
a tempary AnsiString?!?
best regards.
Torben
 
 

Re:Edit1->Text assigment in a sub function

Torben Sandbęk Pedersen wrote:
Quote
r((Edit2->Text)); // this do not work?? Edit2 do NOT change value?
TEdit::Text is a property and unfortunately properties don't always
behave exactly like a variable of the same type. If you think about it
a property is actually two function calls working together (one to
read, one to write). How can you take the address of something that is
two different things? Whatever the solution Borland chose not to bother
implementing it.
It is generally best to assume that you can only assign to or from
them. Anything beyond that may or may not work.
--
Andrue Cope [TeamB]
[Bicester, Uk]
info.borland.com/newsgroups/guide.html
 

Re:Edit1->Text assigment in a sub function

Torben Sandbęk Pedersen wrote:
Quote
r((Edit2->Text)); // this do not work?? Edit2 do NOT change value?
Why cant I use the Edit->Text directly in my function call?, but have to use
a tempary AnsiString?!?
Because Edit->Text when used as argument produces a temporary
AnsiString.
See:
Newsgroups: borland.public.cppbuilder.students
Subject: AnsiString's printf() (BCB6)
Date: Mon, 10 Oct 2005 10:01:02 -0500
Message-ID: < XXXX@XXXXX.COM >
Hans.
 

{smallsort}

Re:Edit1->Text assigment in a sub function

"Torben Sandbęk Pedersen" < XXXX@XXXXX.COM >writes:
Quote
void __fastcall TForm1::Button1Click(TObject *Sender)
{
AnsiString s;
r(s);
Edit1->Text = s; // Edit1 change its value!
r((Edit2->Text)); // this do not work?? Edit2 do NOT change value?
r() does work. It just isn't doing what you expect. When you pass it
Edit2->Text, you are passing a COPY of the data in the Edit2->Text
property. Therefore, when that copy is changed, it is not reflected
in the original string.
Quote
Why cant I use the Edit->Text directly in my function call?, but have to use
a tempary AnsiString?!?
Because the return value from the Edit->Text property is a copy, and
so all the work is not done on the internal data of the object that
you are looking at. (This is necessary in part because the Edit
window control does not store its internal data in an AnsiString, and
therefore it must create a temporary string object each time you ask
to see that data.)
--
Chris (TeamB);