There is nothing "fast" about loading a large amount of text into a TMemo
. It is a UI control, and you are copying the text into the UI's internal buffers. So it is going to take time to load.
But, to help speed up the app's startup, do not put large amounts of text directly in the TMemo
at design-time. It will take time to stream in from the DFM, and that will slow down the Form's creation, as you are experiencing.
Instead, put the text into a separate file and compile it into your app's resources by adding an .rc
file to your project:
MYTEXT RCDATA "mytext.txt"
At runtime, you can then use a TResourceStream
to access the resource data and load it into the TMemo
using its LoadFromStream()
method:
#include <memory>
void TMyForm::LoadMemoText()
{
std::auto_ptr<TResourceStream> strm(new TResourceString(HInstance, "MYTEXT", RT_RCDATA));
Memo1->Lines->LoadFromStream(strm.get());
}
Call LoadMemoText()
whenever you are ready to load the TMemo
text, such as in the form's OnShow
event, or in a timer, or in response to a user action, or whenever you want. That will give the Form a chance to create and show to the user more quickly before you then load the text.
There is no need to put a hidden file on the user's hard drive. You can keep the text embedded inside your .exe
file, just not auto-loaded when the Form is created. Load it when you are ready to load it.