Penny hapeny
2007-12-19 16:32:50 UTC
Hi There,
I am trying to learn Builder from books etc, but have to abandon my efforts
from time to time, perhaps as much as 12 months and find I have forgotten
most of what I have learnt.
Anyway my present problem is with file saving and opening. which I have
bodged to make it work, but would like to do it properly. For example this
is my present code.
void __fastcall TForm1::SaveAs1Click(TObject *Sender)
{
char filename[85] = "Test3.txt" ;
FILE *fileptr;
if (SaveDialog1->Execute())
{
Label16->Caption = ExtractFileName(SaveDialog1->FileName); // If
I hover the mouse over FileName in this line when I have a break point
further along
// it shows what ever name I have
entered in the Save Dialog1 window
}
if ((fileptr = fopen(filename, "w")) == NULL)
// but if I do the same thing here it only shows filename as Test3.txt
// (obtained from the first line in
this function where char filename is defined).
{
Label16->Caption = "error: Cannot open file: Test3.txt";
exit (0);
}
Label16->Caption = "Writing data items to file: Test3.txt ";
fwrite(Grid, sizeof(Grid), 1, fileptr);
fclose(fileptr); /* Close file */
}
This works but only to save the results to Test3.txt The Execute function
brings up a Save Dialog box where I can enter a file name. but the example
only works or saves to Test3.txt
Any help to carry out what must be a simple task is appreciated.
Penny.
I am trying to learn Builder from books etc, but have to abandon my efforts
from time to time, perhaps as much as 12 months and find I have forgotten
most of what I have learnt.
Anyway my present problem is with file saving and opening. which I have
bodged to make it work, but would like to do it properly. For example this
is my present code.
void __fastcall TForm1::SaveAs1Click(TObject *Sender)
{
char filename[85] = "Test3.txt" ;
FILE *fileptr;
if (SaveDialog1->Execute())
{
Label16->Caption = ExtractFileName(SaveDialog1->FileName); // If
I hover the mouse over FileName in this line when I have a break point
further along
// it shows what ever name I have
entered in the Save Dialog1 window
}
if ((fileptr = fopen(filename, "w")) == NULL)
// but if I do the same thing here it only shows filename as Test3.txt
// (obtained from the first line in
this function where char filename is defined).
{
Label16->Caption = "error: Cannot open file: Test3.txt";
exit (0);
}
Label16->Caption = "Writing data items to file: Test3.txt ";
fwrite(Grid, sizeof(Grid), 1, fileptr);
fclose(fileptr); /* Close file */
}
This works but only to save the results to Test3.txt The Execute function
brings up a Save Dialog box where I can enter a file name. but the example
only works or saves to Test3.txt
Any help to carry out what must be a simple task is appreciated.
Penny.