[英]How to load a Text file into Tmemo(Android,C++Builder)
I use C++Builder to make an Android app. 我使用C ++ Builder制作一个Android应用程序。
I try to load a text file into a TMemo
, but there is an error: 我尝试将文本文件加载到TMemo
,但是出现错误:
No mapping for the Unicode charactor exists in the target multibyte code page. 目标多字节代码页中不存在Unicode字符的映射。
I use TDirectory::GetFiles()
to get a list of files and add them to a TListBox
: 我使用TDirectory::GetFiles()
获取文件列表并将其添加到TListBox
:
TStringDynArray list;
TSearchOption searchOption;
searchOption = TSearchOption::soAllDirectories;
list = TDirectory::GetFiles(SYS_TxtDirectory, "*.txt", searchOption);
ListBox1->Items->Clear();
for(int i=0;i<list.Length;i++)
{
ListBox1->Items->Add(list[i]);
}
When I click on the ListBox, I get a filename with full path into this variable: 当我单击列表框时,我得到一个文件名,该文件名包含此变量的完整路径:
AnsiString txtFileName; //store txt filename with full path
I wish to load this file into a TMemo. 我希望将此文件加载到TMemo中。 But these codes cause the error: 但是这些代码会导致错误:
Code 1: 代码1:
Memo1->Lines->LoadFromFile(txtFileName); //<----run to here,error occurred
Code 2: 代码2:
TStringStream * LrcFileStream;
LrcFileStream=new TStringStream();
LrcFileStream->LoadFromFile(txtFileName);
Memo1->Lines->LoadFromStream(LrcFileStream); //<----run to here,error occurred
delete LrcFileStream;
Code 3: 代码3:
TStringDynArray list;
list = TFile::ReadAllLines(LrcFile); //<----run to here,error occurred
Memo1->Lines->Clear();
for(int i=0;i<list.Length;i++)
{
Memo1->Lines->Add(list[i]);
}
Code 4: 代码4:
TStringList *ss=new TStringList();
ss->LoadFromFile(LrcFile); //<----run to here,error occurred
for(int i=0;i<ss->Count;i++)
{
TmpStr=TmpStr+ss->Strings[i];
}
delete ss;
How can I load a text file into a TMemo
? 如何将文本文件加载到TMemo
?
These codes are working on Abdroid now. 这些代码现在可以在Abdroid上使用。
TStringDynArray list;
UnicodeString TmpStr;
list = TFile::ReadAllLines(LrcFile,TEncoding::ANSI);
TmpStr="";
Memo1->Lines->Clear();
for(int i=0;i<list.Length;i++)
{
TmpStr=TmpStr+list[i];
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.