sneeuw
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 ThisProjectDisplayWindowCl ass ;
or, when I have a pointer to the class already :
MyClass MC ;
MC.Display = new ThisProjectDisplayWindowCl ass ;
Now, ThisProjectDisplayWindowCl ass in fact needs to be a class wich takes a few pointers to visual Objects as input (construction).
I thought to do the following :
ThisProjectDisplayWindowCl ass : public DisplayBase
{
ThisProjectDisplayWindowCl ass (AnsiString *Str) ;
~ThisProjectDisplayWindowC lass() ;
Display(char *text) ; // This fnctn is virtual in the base class
}
ThisProjectDisplayWindowCl ass::ThisP rojectDisp layWindowC lass
{
ThisProjectDisplayWindowCl ass::Str = Str ;
}
ThisProjectDisplayWindowCl ass::Displ ay(char *text)
{
*Str = AnsiString(text) ;
}
Now this all compiles great, e.g :
MyClass::Display = new ThisProjectDisplayWindowCl ass(&Capti on) ;
But the String is not really changed ... that is to say ... Caption doesn't change at all ??
When I try :
MyClass::Display = new ThisProjectDisplayWindowCl ass(&Statu sBar->Simp leText) ; 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.
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 ThisProjectDisplayWindowCl
or, when I have a pointer to the class already :
MyClass MC ;
MC.Display = new ThisProjectDisplayWindowCl
Now, ThisProjectDisplayWindowCl
I thought to do the following :
ThisProjectDisplayWindowCl
{
ThisProjectDisplayWindowCl
~ThisProjectDisplayWindowC
Display(char *text) ; // This fnctn is virtual in the base class
}
ThisProjectDisplayWindowCl
{
ThisProjectDisplayWindowCl
}
ThisProjectDisplayWindowCl
{
*Str = AnsiString(text) ;
}
Now this all compiles great, e.g :
MyClass::Display = new ThisProjectDisplayWindowCl
But the String is not really changed ... that is to say ... Caption doesn't change at all ??
When I try :
MyClass::Display = new ThisProjectDisplayWindowCl
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
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
Netminder
Community Support Moderator
Experts Exchange
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.