a question regarding CStringList
-
Why don't you use RemoveAt and GetAt ? First, get the object at a specific position with GetAt, then remove it from the list with RemoveAt, then delete the object.
POSITION Pos = ....; // Some position CObject* pToDelete = YourStringList.GetAt(Pos); YourStringList.RemoveAt(Pos); delete pToDelete;
By the way, I think that the STL containers are much easier to use for particular cases like that. The direct access of the iterator is something very powerfull (no nooooo, I don't want to reopen the debate from yesterday about MFC and STL containers ;P ).yes, you were right... look at the example provided here[^]...
TOXCCT >>> GEII power
[toxcct][VisualCalc 2.20][VCalc 3.0 soon...] -
yes, you were right... look at the example provided here[^]...
TOXCCT >>> GEII power
[toxcct][VisualCalc 2.20][VCalc 3.0 soon...]BTW, I like the way you post code :). How are you doing that ? You change the color manualy for everything or do you use something special to edit code ?
-
BTW, I like the way you post code :). How are you doing that ? You change the color manualy for everything or do you use something special to edit code ?
hum, actually, manually... (for the moment)... but i plan to make a little program which gets the text you post and automatically adds the CP CSS tags for the colors :
<SPAN class=cpp-keyword> keyword </SPAN>
<SPAN class=cpp-comment> //comment </SPAN>
<SPAN class=cpp-preprocessor> #preprocessor </SPAN>
<SPAN class=cpp-string> "string" </SPAN>
<SPAN class=cpp-literal> 123 </SPAN>
TOXCCT >>> GEII power
[toxcct][VisualCalc 2.20][VCalc 3.0 soon...] -
why don't you just do this ? (looking at the MSDN[^]...)
CStringList myList = /*...*/;
//...
CObject* pObj = NULL;
for (int i = 0; i < this->GetCount(); i++) {
//because GetAt() returns a CObject*&
pObj = myList.GetAt(i);
myList.RemoveAt(i);
delete pObj;
}
TOXCCT >>> GEII power
[toxcct][VisualCalc 2.20][VCalc 3.0 soon...] -- modified at 3:39 Tuesday 14th February, 2006hello toxcct... this is what i found in MSDN class CStringList : public CObject Remarks The CStringList class supports lists of CString objects. All comparisons are done by value, meaning that the characters in the string are compared instead of the addresses of the strings. The member functions of CStringList are similar to the member functions of class CObList. Because of this similarity, you can use the CObList reference documentation for member function specifics. Wherever you see a CObject pointer as a return value, substitute a CString (not a CString pointer). Wherever you see a CObject pointer as a function parameter, substitute an LPCTSTR. http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/_mfc_cstringlist.asp[^] so now what?:((
-
Sorry !!! May I know which return value(LPCTSTR) are you talking about. Because none of the functions that I mentioned 'Find' and 'RemoveAt' returns LPCTSTR. So I am confused as what return value you are talking about.
see,itz not abt deleting from the list(yes that is also one requirement)...but what i need to know is how to "delete" teh allocated memory!(by just removing from teh list, the string only get removed from teh list but it does not free the memory associated with teh CString object that i had dynamically created!...that is why i need teh address of teh CString object!...) any ideas?
-
hello toxcct... this is what i found in MSDN class CStringList : public CObject Remarks The CStringList class supports lists of CString objects. All comparisons are done by value, meaning that the characters in the string are compared instead of the addresses of the strings. The member functions of CStringList are similar to the member functions of class CObList. Because of this similarity, you can use the CObList reference documentation for member function specifics. Wherever you see a CObject pointer as a return value, substitute a CString (not a CString pointer). Wherever you see a CObject pointer as a function parameter, substitute an LPCTSTR. http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/_mfc_cstringlist.asp[^] so now what?:((
this is for danta handling into the list... but if you use the C++
delete
keyword, you have to give it the address to the memory block to delete
TOXCCT >>> GEII power
[toxcct][VisualCalc 2.20][VCalc 3.0 soon...] -
Why don't you use RemoveAt and GetAt ? First, get the object at a specific position with GetAt, then remove it from the list with RemoveAt, then delete the object.
POSITION Pos = ....; // Some position CObject* pToDelete = YourStringList.GetAt(Pos); YourStringList.RemoveAt(Pos); delete pToDelete;
By the way, I think that the STL containers are much easier to use for particular cases like that. The direct access of the iterator is something very powerfull (no nooooo, I don't want to reopen the debate from yesterday about MFC and STL containers ;P ).hello cedric! actually that what i did!...he is the small snippet!....i get an error!
CObject* pObject1; pObject1 = myList1->GetAt(myList1->FindIndex( 0 ));//ERROR!!!!! myList1->RemoveAt(myList1->FindIndex( 0 )); delete pObject1;
error C2679: binary '=' : no operator defined which takes a right-hand operand of type 'class CString' (or there is no acceptable conversion)
what do i do?any ideas?:sigh:
-
hum, actually, manually... (for the moment)... but i plan to make a little program which gets the text you post and automatically adds the CP CSS tags for the colors :
<SPAN class=cpp-keyword> keyword </SPAN>
<SPAN class=cpp-comment> //comment </SPAN>
<SPAN class=cpp-preprocessor> #preprocessor </SPAN>
<SPAN class=cpp-string> "string" </SPAN>
<SPAN class=cpp-literal> 123 </SPAN>
TOXCCT >>> GEII power
[toxcct][VisualCalc 2.20][VCalc 3.0 soon...]toxcct wrote:
but i plan to make a little program which gets the text you post and automatically adds the CP CSS tags for the colors :
Sure, sure!
Owner drawn Jesus Loves
-
hello cedric! actually that what i did!...he is the small snippet!....i get an error!
CObject* pObject1; pObject1 = myList1->GetAt(myList1->FindIndex( 0 ));//ERROR!!!!! myList1->RemoveAt(myList1->FindIndex( 0 )); delete pObject1;
error C2679: binary '=' : no operator defined which takes a right-hand operand of type 'class CString' (or there is no acceptable conversion)
what do i do?any ideas?:sigh:
What is the type of myList1 ?? From the MSDN:
CObject*& GetAt(
POSITION position
);Are you sure the error comes at this line ?
-
What is the type of myList1 ?? From the MSDN:
CObject*& GetAt(
POSITION position
);Are you sure the error comes at this line ?
yeah!....u see as long as i typecast it to LPCTSTR and that too to an LPCTSTR i dont get an error..... in teh MSDN it says that for CStringList teh returned parameter will alwayz be replaced from CString* to LPCTSTR..... so is there a way of getting CString* from LPCTSTR?.....i mean after all LPCTSTR is a pointer inside the CString object!