Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » LineEdit, EditFields, DocEdit » DocEdit call RemoveLines make Assertion failed.
icon9.gif  DocEdit call RemoveLines make Assertion failed. [message #14358] Sat, 23 February 2008 17:17 Go to next message
HenryXin is currently offline  HenryXin
Messages: 10
Registered: February 2008
Promising Member
Hi,
I am a newbie about upp. I inherit from DocEdit to display this filesystem content, insert filenames, when beyond 200 line, remove lines as following:

#define MAX_CACHE_LINE 200
class MyDocEdit : public DocEdit
{
String inputString;
static String tipString;
String dir;
public:
virtual bool Key(dword key, int count);
MyDocEdit()
{
ShowTip();
}
void ShowTip();
int RunCommand(String user_input);
};

String MyDocEdit::tipString(">");
void MyDocEdit::ShowTip()
{
dir = GetCurrentDirectory();
Insert(cursor, dir+tipString);
this->SetCursor(cursor+(dir+tipString).GetLength());
inputString.Clear();
}

bool MyDocEdit::Key(dword key, int count)
{
switch(key & ~(K_CTRL | K_ALT | K_SHIFT)) {
case K_ENTER:
RunCommand(inputString);
inputString.Clear();
if(this->GetLineCount() > MAX_CACHE_LINE) {

this->RemoveLines(0, this->GetLineCount() - MAX_CACHE_LINE);
ClearLines();
sprintf(str, "%d %d", this->GetLineCount(), (this->GetLineCount() - MAX_CACHE_LINE));
}
ShowTip();

return true;
default:
if(!(key & 0x10000) && !(key & 0x110000)) {
inputString +=(char)key;
}
break;
}

return DocEdit::Key(key, count);
}

int MyDocEdit::RunCommand(String user_input)
{
FindFile ff;
Insert(GetCursor(), "\n");
cursor++;
if(!ff.Search(AppendFileName(dir, "*")))
return false;
do {

Insert(GetCursor(), ff.GetName()+"\n");

SetCursor(GetCursor()+ff.GetName().GetLength()+1);
}
while(ff.Next());
return 0;
}

When lines are beyond 200, Assert failed in C:\upp\uppsrc\CtrlLib\DocEdit.cpp, line 25
this->line.GetCount() == para.GetCount().

I don't find the reason now.
Thanks.

[Updated on: Sat, 23 February 2008 17:20]

Report message to a moderator

icon7.gif  Re: DocEdit call RemoveLines make Assertion failed. [message #14371 is a reply to message #14358] Sun, 24 February 2008 08:12 Go to previous messageGo to next message
HenryXin is currently offline  HenryXin
Messages: 10
Registered: February 2008
Promising Member
I have found the reason, need line.Remove() before RemoveLines().
It seems strange, why need two function?

line.Remove(0, remove_num); RemoveLines(0, remove_num);
Re: DocEdit call RemoveLines make Assertion failed. [message #14450 is a reply to message #14371] Tue, 26 February 2008 21:11 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
You should not, Remove should be enough (Remove calls RemoveLines).

RemoveLines only signals to derived class that lines were removed. Default implementation is empty. Check docs Smile

Mirek
Re: DocEdit call RemoveLines make Assertion failed. [message #14470 is a reply to message #14450] Wed, 27 February 2008 03:55 Go to previous messageGo to next message
HenryXin is currently offline  HenryXin
Messages: 10
Registered: February 2008
Promising Member
Thank for your reply.
But I try it only using line.Remove(0, remove_num);
But Fatal Error:
Assertion failed in C:\upp\uppsrc/Core/Vcont.h, line 17
i >=0 && i < item.

I read the code:
DocEdit inherit from TextCtrl has the memeber:
Vector<Ln> line;
and it defines its member:
Vector<Para> para;
So only call line.Remove(), when call the parm.Remove()?
And the void DocEdit::RemoveLines(int line, int count) is strange?
void DocEdit::RemoveLines(int line, int count)
{
para.Remove(line, count);
ASSERT(this->line.GetCount() == para.GetCount());
}
It removes para, but check the line == para?

Best Regards
Henry
Re: DocEdit call RemoveLines make Assertion failed. [message #14477 is a reply to message #14470] Wed, 27 February 2008 09:41 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
HenryXin wrote on Tue, 26 February 2008 21:55

Thank for your reply.
But I try it only using line.Remove(0, remove_num);
But Fatal Error:
Assertion failed in C:\upp\uppsrc/Core/Vcont.h, line 17
i >=0 && i < item.

I read the code:
DocEdit inherit from TextCtrl has the memeber:
Vector<Ln> line;
and it defines its member:
Vector<Para> para;
So only call line.Remove(), when call the parm.Remove()?
And the void DocEdit::RemoveLines(int line, int count) is strange?
void DocEdit::RemoveLines(int line, int count)
{
para.Remove(line, count);
ASSERT(this->line.GetCount() == para.GetCount());
}
It removes para, but check the line == para?

Best Regards
Henry



I am sorry, I was under impression that we are talking about LineEdit... Well, DocEdit really does overload RemoveLines. 'para' works as cache of paragraph metrics (height for given width).

Means that if you override RemoveLines for DocEdit, you should call DocEdit::RemoveLines there... (must add that info to docs).

Other than that, I suggest posting a more complete code.

Mirek
Re: DocEdit call RemoveLines make Assertion failed. [message #14514 is a reply to message #14477] Thu, 28 February 2008 03:31 Go to previous messageGo to next message
HenryXin is currently offline  HenryXin
Messages: 10
Registered: February 2008
Promising Member
Thanks.
I post the inherit class code: (It has been posted in the start)
class MyDocEdit : public DocEdit
{
Thread timerthread;
String inputString;
static String tipString;
String dir;
public:
virtual bool Key(dword key, int count);
MyDocEdit();
void ShowTip();
int RunCommand(String user_input);
void UpdateData();
void InsertData();
};
//////////////////////////////////////////////////
Actually, I don't override the RemoveLines().So the call RemoveLines() should be DocEdit::RemoveLines(). This means the DocEdit::RemoveLines() doesn't work well?
Re: DocEdit call RemoveLines make Assertion failed. [message #14570 is a reply to message #14514] Mon, 03 March 2008 20:43 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
I am sorry, this is still too little to identify the problem.

Please a testcase. Something we can unzip as package and compile. Means, create a short code that demonstrates the problem in the form of package, make sure it compiles and exhibits it, then .zip it and post here.

Saves a lot of time and void discussion... Wink

Mirek
Re: DocEdit call RemoveLines make Assertion failed. [message #14682 is a reply to message #14570] Sat, 08 March 2008 10:48 Go to previous messageGo to next message
HenryXin is currently offline  HenryXin
Messages: 10
Registered: February 2008
Promising Member
Smile That's good, I post my simple test package. Thanks.
Re: DocEdit call RemoveLines make Assertion failed. [message #14684 is a reply to message #14682] Sat, 08 March 2008 16:58 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
I see. I guess I was not clear enough Smile

You are NOT supposed to call RemoveLines. RemoveLines is called by DocEdit to tell you that lines were removed (AFTER they were removed by calling "Remove" directly or by user).

What do you want to achieve?

If to keep the "log buffer" to MAX_CACHE_LINES, then use this:

bool MyDocEdit::Key(dword key, int count)
{
	switch(key & ~(K_CTRL | K_ALT | K_SHIFT)) {
		case K_ENTER:
			RunCommand(inputString);
			inputString.Clear();
			if(GetLineCount() > MAX_CACHE_LINE)
				Remove(0, GetPos(GetLineCount() - MAX_CACHE_LINE));
			ShowTip();
			return true;
		default:
			if(!(key & 0x10000) &&  !(key & 0x110000)) { 
				inputString +=(char)key;
			}
			break;
	}
	
	return DocEdit::Key(key, count);
}


Mirek
icon14.gif  Re: DocEdit call RemoveLines make Assertion failed. [message #14690 is a reply to message #14684] Sun, 09 March 2008 06:03 Go to previous message
HenryXin is currently offline  HenryXin
Messages: 10
Registered: February 2008
Promising Member
It works well Very Happy .Thanks, I will need read the code more...
Previous Topic: Best way to implement a two-way LineEdit
Next Topic: Enter time as duration
Goto Forum:
  


Current Time: Thu Mar 28 18:20:31 CET 2024

Total time taken to generate the page: 0.01034 seconds