Sitemap
C++ Builder

Latest News about C++ Builder

How to add strings in modern C++ Builder

--

In modern C++, if you are developing a global application you must use Unicode Strings to support all language letters in your components, databases and other tools. Here I listed how to add strings faster for five different components in RAD Studio / C++ Builder

Get Yilmaz Yoru’s stories in your inbox

Join Medium for free to get updates from this writer.

Adding Unicode Strings to TStringList in C++ Builder

TStringList *strl=new(TStringList);
unsigned long int start=GetTickCount();
strl->BeginUpdate();
for(int i=0; i<1000; i++)
{
strl->Add(“abcdefghijkl”);
}
strl->EndUpdate();
Memo1->Lines->Add(“TStringlist Duration: “+IntToStr((int) GetTickCount()-start))+” ms”);
strl->Free();

Adding Unicode Strings to Memo box in C++ Builder

Memo1->Enabled=false;
Memo1->EnabledScroll=false;
Memo1->ShowScrollBars=false;
unsigned long int start=GetTickCount();Memo1->Lines->BeginUpdate();
for(int i=0; i<1000; i++)
{
Memo1->Lines->Add(“abcdefghijkl”);
}
Memo1->Lines->EndUpdate();
Memo1->Lines->Add(“TMemo Duration: “+IntToStr((int)(GetTickCount()-start))+” ms”);
Memo1->Enabled=true;
Memo1->EnabledScroll=true;
Memo1->ShowScrollBars=true;

Adding Unicode Strings to ListBox in C++ Builder

ListBox1->Enabled=false;
ListBox1->ShowScrollBars=false;
unsigned long int start=GetTickCount();ListBox1->BeginUpdate();
for(int i=0; i<1000; i++)
{
ListBox1->Items->Add("abcdefghijkl");
}
ListBox1->EndUpdate();
ListBox1->Items->Add("TListBox Duration: "+IntToStr((int)(GetTickCount()-start))+" ms");
ListBox1->Enabled=true;
ListBox1->ShowScrollBars=true;

Adding Unicode Strings to ListBox in C++ Builder

TListViewItem *TI;ListView1->Enabled=false;
//ListView1->ShowScrollBars=false;
unsigned long int start=GetTickCount();
ListView1->BeginUpdate();
for(int i=0; i<1000; i++)
{
TI = ListView1->Items->Add();
TI->Text="abcdefghijkl";
}
ListView1->EndUpdate();
TI = ListView1->Items->Add();
TI->Text="ListView Duration: "+IntToStr((int)(GetTickCount()-start))+" ms";
ListView1->Enabled=true;
//ListView1->ShowScrollBars=true;

Adding Unicode Strings to StringGrid in C++ Builder

StringGrid1->Enabled=false;
StringGrid1->ShowScrollBars=false;
StringGrid1->RowCount=1002;
unsigned long start=GetTickCount();
StringGrid1->BeginUpdate();
for(int i=0; i<1000; i++)
{
StringGrid1->Cells[0][i]="abcdefghijkl";
}
StringGrid1->EndUpdate();
StringGrid1->Cells[0][i]="StringGrid Duration: "+IntToStr((int)(GetTickCount()-start))+" ms";
StringGrid1->Enabled=true;
StringGrid1->ShowScrollBars=true;

If you don’t use there are less durations in most components and higher duration in ListBox component as listed below.

1. StringList1->Add(“abcdefghijkl”); // Duration: 0 ms2. Memo1->Lines->Add(“abcdefgh?kl”); //Duration: 47ms3. ListBox1->Items->Add(“abcdefghijkl”); // Duration 32578 ms4. TListViewItem1->Add(); TListViewItem1->Text=”abcdefghijkl”; // Duration 31 ms5. StringGrid1->Cells[0][i]=”abcdefghijkl”; // Duration: 0 ms

Consequently, if you have a lot of strings to add to these components; thebest way is using BeginUpdate() and EndUpdate() methods for all StringList, Memo, ListView, ListBox, StringGrid components.

--

--

Yilmaz Yoru
Yilmaz Yoru

Written by Yilmaz Yoru

Mechanical Engineer (MSc PhD), Developer, Founder of Esenja Company, Embarcadero C++ Builder MVP