Is there a faster component than TMemo on CodeGear C++ Builder?
I'm using CodeGear C++ Builder 2009 and have problems with the TMemo component. I开发者_StackOverflow中文版t's too slow. I use it to display ASCII text from the COM serial port. I need to display every single symbol when it comes from the COM Serial port. The problem is, if there is a lot of text from the COM serial port, older text on TMemo starts to flicker and all the more text is on the component, the worse it gets. When TMemo contains 1000 lines of text, refresh delay is enormous!
I set doubleBuffered property to true, but this not helping a all. How they make refresh time to be minimum in applications like SecureCRT? New text is added smoothly and there is no flickering. Which component can produce such result?
Rather than displaying the characters in real-time to the TMemo as they arrive, try saving them to an in-memory buffer first, and then have a short timer copy the buffer into the TMemory periodically, and make use of the Lines->BeginUpdate()
and Lines->EndUpdate()
methods when adding new text. Also, 1000 lines is a lot, you may have to start removing older lines as newer lines are added after awhile. I usually limit my TMemo
controls to a few hundred lines at a time.
Update: try something like this:
TMemoryStream *Buffer;
// serial port callback
void BytesReceived(void *Data, int Length)
{
Buffer->Position = Buffer->Size;
Buffer->WriteBuffer(Data, Length);
}
__fastcall TForm1::TForm1(TComponent *Owner)
: TForm(Owner)
{
Buffer = new TMemoryStream;
}
__fastcall TForm1::~TForm1()
{
delete Buffer;
}
void __fastcall TForm1::TimerElapsed(TObject *Sender)
{
if (Buffer->Size > 0)
{
Memo1->Lines->BeginUpdate();
Memo1->SelStart = Memo1->GetTextLen();
Memo1->SelLength = 0;
Memo1->SelText = AnsiString((char*)Buffer->Memory, Buffer->Size);
Memo1->SelStart = Memo1->GetTextLen();
Memo1->Perform(EM_SCROLLCARET, 0, 0);
Memo1->Lines->EndUpdate();
Buffer->Clear();
}
}
as for window devices, . .
best way is uses thread event instead of timer event, . .
place serial wait event inside thread->execute()
, (this is a do while loop, . .)
serial wait event will do nothing until something received,..
soon it received into a *buffer
, check length of buffer/string, . .
then place in memo as
memo->text=buffer;
or
memo->lines-add(buffer);
精彩评论