SRL Archive - Delphi/FPC Help and Tutorials

an other question, saving on exit and loading on create


Awkwardsaw

2009-06-04 06:50:08

what would be the correct way of loading a text document on create(tform) and saving it on exit?

so far, this is what i have:

procedure TForm1.FormCreate(Sender: TObject);
begin
fileData.LoadFromFile('notes.txt');
memo1.Text := filedata;
end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
if radiobutton1.Checked = true then
begin
memo1.Text := filedata;
if FileExists('Notes.txt') then fileData.SaveToFile('Notes.txt') else
begin
FileCreate('Notes.txt');
fileData.SaveToFile('Notes.txt')
end;
end;
end;

apparently, that's not right, or i wouldn't be posting :p

ps: a link to a great delphi learning/ tut site would be great, i can never find one on google -.-

Nava2

2009-06-04 06:53:42

About.com is a great source for tutorials…

Sorry, I'm not sure how you would do it. :(

Awkwardsaw

2009-06-04 06:58:32

thanks any ways nava :P

if im not looking around on Google, im on about.com =p

that's all either really basic stuff, really advanced stuff, or stuff that i have no need for, unfortunately

Miitchyy

2009-06-05 01:35:43

procedure TForm1.FormCreate(Sender: TObject);
begin
fileData.LoadFromFile('Notes.txt');
memo1.Text := fileData;
end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
if radiobutton1.Checked then
begin
fileData := memo1.Text;
if FileExists('Notes.txt') then fileData.SaveToFile('Notes.txt') else
begin
FileCreate('Notes.txt');
fileData.SaveToFile('Notes.txt')
end;
end;
end;

Is fileData a TStringsList?

I'm basically going off memory because I don't have Delphi anymore.
All I really did was reverse memo1.Text := fileData. So it saves what you've put rather then what was already in the file

Awkwardsaw

2009-06-05 03:52:03

From: Kevin Wolf aka Miitchyy
procedure TForm1.FormCreate(Sender: TObject);
begin
fileData.LoadFromFile('Notes.txt');
memo1.Text := fileData;
end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
if radiobutton1.Checked then
begin
fileData := memo1.Text;
if FileExists('Notes.txt') then fileData.SaveToFile('Notes.txt') else
begin
FileCreate('Notes.txt');
fileData.SaveToFile('Notes.txt')
end;
end;
end;

Is fileData a TStringsList?

I'm basically going off memory because I don't have Delphi anymore.
All I really did was reverse memo1.Text := fileData. So it saves what you've put rather then what was already in the file


thanks :P

when i get on delphi i'll try it out, and yes filedata was a tstringslist