1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
| void __fastcall TForm1::Button2Click(TObject *Sender)
{
char szFileName[256+4];
int iFileHandle;
int iLength;
if (SaveDialog1->Execute())
{
if (FileExists(SaveDialog1->FileName))
{
fnsplit(SaveDialog1->FileName.c_str(), 0, 0, szFileName, 0);
strcat(szFileName, ".BAK");
RenameFile(SaveDialog1->FileName, szFileName);
}
iFileHandle = FileCreate(SaveDialog1->FileName);
// Ecrit le nombre de lignes et de colonnes de la grille.
// FileWrite(iFileHandle, (char*)&(StringGrid1->ColCount), sizeof(StringGrid1->ColCount));
// FileWrite(iFileHandle, (char*)&(StringGrid1->RowCount), sizeof(StringGrid1->RowCount));
for (int x=0;x<Memo1->Lines->Count;x++)
{
// for (int y=0;y<StringGrid1->RowCount;y++)
// {
// Ecrit la longueur de chaque chaîne, suivie de la chaîne elle-même.
// iLength = StringGrid1->Cells[x][y].Length();
// FileWrite(iFileHandle, (char*)&iLength, sizeof(iLength));
FileWrite(iFileHandle, Memo1->Lines->operator [](x).c_str() /*StringGrid1->Cells[x][y].c_str()*/, Memo1->Lines->operator [](x).Length() /*StringGrid1->Cells[x][y].Length()*/);
// }
}
FileClose(iFileHandle);
}
} |
Partager