I have program which loads and saves file. When saving, I use the following:
This stores the size of the text, then the text itself. This works OK, but how do I read the text again into an AnsiString? eg.
I have tried various methods, but I get either blank strings or access violations. Please help.
Code:
AnsiString Text = "bla bla bla";
int TextSize = Text.Length();
int FileHandle = FileCreate("c:\\something.txt");
FileWrite(FileHandle, (char *)&TextSize, sizeof(TextSize));
FileWrite(FileHandle, Text.c_str(), TextSize);
FileClose(FileHandle);
Code:
AnsiString RetrievedText;
int TextSize;
int FileHandle = FileOpen("c:\\something.txt", fmOpenRead);
FileRead(FileHandle, (char *)&TextSize, sizeof(TextSize));
//What goes here to read the string into RetrievedText?
FileClose(FileHandle);