LastCyborg
Programmer
Is there a way to pass as a parameter an instance of a TStringList Class???
In other words I need to create a class constructor that has it as parameter.
Here is some code of what I'm doing
//---------------------------------------------------------------------------
.h
//---------------------------------------------------------------------------
class TMyClass : public TObject
{
public:
TStringList *TheList;
__fastcall TMyClass (TStringList *StringList);
__fastcall ~TMyClass ();
};
//---------------------------------------------------------------------------
.cpp
//---------------------------------------------------------------------------
__fastcall TMyClass::TMyClass (TStringList *StringList)
{
TheList = new TStringList ();
TheList = StringList;
}
//---------------------------------------------------------------------------
__fastcall TMyClass::~TMyClass ()
{
delete TheList;
}
//---------------------------------------------------------------------------
Using my Object
//---------------------------------------------------------------------------
any event handler
{
MyObject = new TMyClass (dynamic_cast<TStringList *>(RichEdit1->Lines));
...
// some operations with the StringList
...
// sending the StringList to the RichEdit
...
delete MyObject;
}
//---------------------------------------------------------------------------
The problem is in the constructor, because when the object receives the parameter this is NULL (before the asign of TheList = StringList).
So, the question is about the StringList as a Parameter, why is NULL?
In other words I need to create a class constructor that has it as parameter.
Here is some code of what I'm doing
//---------------------------------------------------------------------------
.h
//---------------------------------------------------------------------------
class TMyClass : public TObject
{
public:
TStringList *TheList;
__fastcall TMyClass (TStringList *StringList);
__fastcall ~TMyClass ();
};
//---------------------------------------------------------------------------
.cpp
//---------------------------------------------------------------------------
__fastcall TMyClass::TMyClass (TStringList *StringList)
{
TheList = new TStringList ();
TheList = StringList;
}
//---------------------------------------------------------------------------
__fastcall TMyClass::~TMyClass ()
{
delete TheList;
}
//---------------------------------------------------------------------------
Using my Object
//---------------------------------------------------------------------------
any event handler
{
MyObject = new TMyClass (dynamic_cast<TStringList *>(RichEdit1->Lines));
...
// some operations with the StringList
...
// sending the StringList to the RichEdit
...
delete MyObject;
}
//---------------------------------------------------------------------------
The problem is in the constructor, because when the object receives the parameter this is NULL (before the asign of TheList = StringList).
So, the question is about the StringList as a Parameter, why is NULL?