Link to home
Start Free TrialLog in
Avatar of sneeuw
sneeuwFlag for Belgium

asked on

Passing ptr to AnsiString (of visual component) via class constructor and changing content doesn't seem to work

Hi,

Using Borland c++ Builder 5 but I hope the Delphi experts know this one too !??  I guess it's too much Borland to post this question in the c++ forum ?

In my class Model I have a situation where one of the members of the class is a pointer to another class, a class that takes care of visual stuff (e.g. updating StatusBar).

e.g.
class MyClass
{
MyClass() ;
~MyClass() ;
static DisplayClass *Display ;
}

In the main code I want to assign a pointer to a class which suits that particular project best, e.g. :

MyClass::Display = new ThisProjectDisplayWindowClass ;
or, when I have a pointer to the class already :
MyClass MC ;
MC.Display = new ThisProjectDisplayWindowClass ;

Now, ThisProjectDisplayWindowClass in fact needs to be a class wich takes a few pointers to visual Objects as input (construction).

I thought to do the following :
ThisProjectDisplayWindowClass : public DisplayBase
{
ThisProjectDisplayWindowClass (AnsiString *Str) ;
~ThisProjectDisplayWindowClass() ;
Display(char *text) ; // This fnctn is virtual in the base class
}
ThisProjectDisplayWindowClass::ThisProjectDisplayWindowClass
{
ThisProjectDisplayWindowClass::Str = Str ;
}
ThisProjectDisplayWindowClass::Display(char *text)
{
*Str = AnsiString(text) ;
}

Now this all compiles great, e.g :
MyClass::Display = new ThisProjectDisplayWindowClass(&Caption) ;

But the String is not really changed ... that is to say ... Caption doesn't change at all ??

When I try :
MyClass::Display = new ThisProjectDisplayWindowClass(&StatusBar->SimpleText) ;  This doesn't compile for a reason I also don't understand ??

Are there things to VCL I'm missing here ?
Can't this be done using visual VCL components ??

I hope Delphi is more or less the same (I have no idea) ?
But in the C++ forum everybody seems to know VC very good, yet Borland cpp Builder is less known.


ASKER CERTIFIED SOLUTION
Avatar of kretzschmar
kretzschmar
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Hamlet081299
Hamlet081299

I agree with kretzschmar, it's because it's a property.

You should assign the string in the property to a local variable, and then pass that to your method.  Also if the method changes the string then make sure you also assign the local variable back to the property.
sneeuw,

These questions are still open and our records show you logged in recently. Please resolve them appropriately as soon as possible. Continued disregard of your open questions will result in the force/acceptance of a comment as an answer; other actions affecting your account may also be taken. I will revisit these questions in approximately seven (7) days. Please note that the recommended minimum for an "Easy" question is 50 points.
https://www.experts-exchange.com/jsp/qShow.jsp?ta=winprog&qid=20183446
https://www.experts-exchange.com/jsp/qShow.jsp?ta=winprog&qid=20158806
https://www.experts-exchange.com/jsp/qShow.jsp?ta=cplusprog&qid=20192985
https://www.experts-exchange.com/jsp/qShow.jsp?ta=cplusprog&qid=20151309
https://www.experts-exchange.com/jsp/qShow.jsp?ta=cplusprog&qid=20137274
https://www.experts-exchange.com/jsp/qShow.jsp?ta=cplusprog&qid=20136466
https://www.experts-exchange.com/jsp/qShow.jsp?ta=cplusprog&qid=20112991
https://www.experts-exchange.com/jsp/qShow.jsp?ta=delphi&qid=20088277
https://www.experts-exchange.com/jsp/qShow.jsp?ta=javascript&qid=20183228

EXPERTS: Please leave your thoughts on this question here.

Thanks,

Netminder
Community Support Moderator
Experts Exchange
Force/accepted by

Netminder
Community Support Moderator
Experts Exchange