Board index » cppbuilder » Pointer reference

Pointer reference

How can I make Text property of TEdit point to a char* ( or some other
pointer).

My goal is to assign an element from my structure to a TEdit.

Exemple:

Struct
{
    char  *Name;

Quote
};

I Would like Edit1->Text to point to Struct.Name that way when the value
in
my structure changes so will the content of my edit box.

Thanks, Marty.
Email: mbertr...@nitrex.com

 

Re:Pointer reference


Can't be done that way.  You'll have to have a separate function that does
the changing, you can't change where an AnsiString points to, as it always
points to it's internal data.

Something like this (proper error checking removed just to demonstrate the
main point):

void MyFunc(char *str)
{
    MyStruct.Name = str;
    MyEdit->Text = str;

Quote
}

Gambit
Quote
Martin, Bertrand <mbertr...@nitrex.com> wrote in message

news:3981ABE9.71B908CE@nitrex.com...
Quote
> I Would like Edit1->Text to point to Struct.Name that way when the value
> in my structure changes so will the content of my edit box.

Re:Pointer reference


Quote
"Martin, Bertrand" <mbertr...@nitrex.com> writes:
> How can I make Text property of TEdit point to a char* ( or some other
> pointer).

You can't.

Quote
> My goal is to assign an element from my structure to a TEdit.

That's ok.

Quote
> Exemple:

> Struct
> {
>     char  *Name;
> };

That won't work.

Quote
> I Would like Edit1->Text to point to Struct.Name that way when the
> value in my structure changes so will the content of my edit box.

That can't be done.  The Edit box's data is stored in the windows
control itself, and that cannot be changed.  The best you can do is
write a class that has private data that is accessible through
functions (or properties, if you're into that) and the setter function
updates the edit box as well as updating the internal data.

But even so, it'd be easy for the two objects to get out of sync.

What you want will be very brittle, and when anything changes you may
find it breaks.

Why can't your structure just know about the editbox, and provide
access to get/set the data of the editbox without having a local copy?

Then they're always in sync because there is only one place the data
is stored -- in the edit box itself.

--
Chris (TeamB);

Other Threads