13,826
社区成员
发帖
与我相关
我的任务
分享
#include <dialogs.hpp>
void __fastcall TForm1::Button1Click(TObject *Sender)
{
for (int i = 0; i <StringGrid1->RowCount; i++)
StringGrid1->Rows[i]->Clear();
String strFileName;
TOpenDialog *dlgOpen = new TOpenDialog(this);
if (dlgOpen->Execute())
{
strFileName = dlgOpen->FileName;
TStringList *lstFile = new TStringList;
TStringList *lstLine = new TStringList;
lstFile->LoadFromFile(strFileName);
StringGrid1->RowCount = lstFile->Count + 1;
lstLine->Delimiter = ' ';
for (int i = 0; i < lstFile->Count; i++)
{
lstLine->DelimitedText = lstFile->Strings[i];
for (int j = 0; j < lstLine->Count; j++)
{
StringGrid1->Cells[i + 1][j + 1] = lstLine->Strings[j];
}
}
delete lstLine;
delete lstFile;
}
delete dlgOpen;
}