0

As a beginner I have a little problem. I've finished conception of a little application developed in C++ Builder. I've used a Tmemo that has huge amount of texts in order to use them in my application. in the load I've noticed that when the Tmemo have huge data in concepton, it decelerate the load .and the app can be shown after 3/4 seconds or sometimes more! So I decided to use a file that contains all the texts. And using TstringList it works perfectly and runs fast, but I don't want the data to be shown for the open eye.

So I'm asking if there is a way to hide the text file from the user that the app can use and load its information fast.

Buddy
  • 10,874
  • 5
  • 41
  • 58

2 Answers2

0

WINDOWS: You can do it by calling SetFileAttributes and setting the FILE_ATTRIBUTE_HIDDEN flag. See http://msdn.microsoft.com/en-us/library/aa365535%28VS.85%29.aspx

LINUX: just create your file starting with dot. (.filename)

0

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.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770