RemoveLine, error index out of bounds

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
User avatar
Nucleorion
Knows some wx things
Knows some wx things
Posts: 45
Joined: Sat Jan 07, 2017 10:08 pm

RemoveLine, error index out of bounds

Post by Nucleorion »

I like remove a line of wxTextFile opened.

I try:

Code: Select all

	wxString strPerfil="Line of text";	
	wxString itemPerfil;
	wxTextFile file( wxT("ProfileList.txt") );
	file.Open();

	for ( itemPerfil = file.GetFirstLine(); !file.Eof(); itemPerfil = file.GetNextLine() ){
		if(itemPerfil==strPerfil){
			file.RemoveLine(file.GetCurrentLine());
		}
	 }	
	 
	file.Write();
	file.Close();
   	 
And:

Code: Select all

	for ( itemPerfil = file.GetFirstLine(); file.GetCurrentLine()<file.GetLineCount(); itemPerfil = file.GetNextLine() ){
		if(itemPerfil==strPerfil){
			file.RemoveLine(file.GetCurrentLine());
			//strPerfil="";
		}
    }
But if I delete the last filled line I get error index out of bounds in execution time.

How is the right way of remove line of file?
User avatar
doublemax
Moderator
Moderator
Posts: 19159
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: RemoveLine, error index out of bounds

Post by doublemax »

Which wxWidgets version? This is a known bug and should be fixed in the latest development version from GIT.

http://trac.wxwidgets.org/ticket/17283
Use the source, Luke!
User avatar
Nucleorion
Knows some wx things
Knows some wx things
Posts: 45
Joined: Sat Jan 07, 2017 10:08 pm

Re: RemoveLine, error index out of bounds

Post by Nucleorion »

Latest stable version 3.0.2

I understand what do patch http://trac.wxwidgets.org/attachment/ti ... 83.2.patch

I like modifi code for fix this problem. I'm very noob for Latest Development Release: 3.1.0
User avatar
doublemax
Moderator
Moderator
Posts: 19159
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: RemoveLine, error index out of bounds

Post by doublemax »

This is the change you need to perform:
http://trac.wxwidgets.org/changeset/023 ... -wxWidgets

As you can see, you only need to replace one line in one file (the other changes are not relevant for the function). Open <wxdir>/include/wx/textbuf.h and replace line 128 with the "green" one from the patch and rebuild wxWidgets.
Use the source, Luke!
User avatar
Nucleorion
Knows some wx things
Knows some wx things
Posts: 45
Joined: Sat Jan 07, 2017 10:08 pm

Re: RemoveLine, error index out of bounds

Post by Nucleorion »

Ah! ok. I try now :)

Also I find solution for code :P

Code: Select all

	wxString itemPerfil;
	int i;
	file.Open();//abre el archivo
	for ( itemPerfil = file.GetFirstLine(); file.GetCurrentLine()<file.GetLineCount(); i++){
		if(itemPerfil==strPerfil && itemPerfil!=""){
			file.RemoveLine(file.GetCurrentLine());
		}
		if(file.GetCurrentLine()<file.GetLineCount()){
			itemPerfil = file.GetNextLine();
		}

    }
	file.Write();//escribe
	file.Close();//cierra archivo
User avatar
Nucleorion
Knows some wx things
Knows some wx things
Posts: 45
Joined: Sat Jan 07, 2017 10:08 pm

Re: RemoveLine, error index out of bounds

Post by Nucleorion »

Ops! Rebuild again. Ok.

I had to build it on another computer. At the moment I will use the code solution if you do not see any inconvenience.

Very Thaks
Post Reply