Board index » delphi » Save File OnClose, Save information to all files??

Save File OnClose, Save information to all files??

Sorry for the back to back posting, even though they are different topics.
Just do not like posting like this anymore.
Just have to sometimes, when you are at your wits end.

Thank You

_____now question and hopefully someone with an answer_______

  Hello all;
I have ran into a slight dilemma.

   I am loading files into the editor by use of the

procedure TForm1.MenuItem1.Click(Sender: TObject);
begin
Editor.lines. LoadFromFile('file1.dat');
end

procedure TForm1.MenuItem2.Click(Sender: TObject);
and so on, and so on, and so on, and so on, and so on!

procedure TForm1.FormClose(Sender: TObject);
begin
Editor.lines. SaveToFile('file1.dat');
//  their are 144-files listed just like this.
end

But this is causing a major problem though.

  Their are currently 144 .dat files that you can choose to load into the
editor. By use of PopupMenu items.
. When closing I have each file in the OnClose event,
So their are 144 files listed in the OnClose Event.

  I need a way to save the files when you close the program, without any
user interaction what so ever.
This is the unique interface that I want for this version of the software.

  Is their another means of saving the files that will not cause them to
over ride each other
when the form closes.

  I am going to go and try a few things now, But please any suggestions on
this matter will be very grateful.
Thank you

Wayne

 

Re:Save File OnClose, Save information to all files??


Perhaps something like this (assumes each menu item caption is the name of a
file)....

...OnMenuItem.Click...
var CurrentFile : TFileName;
begin
  CurrentFile := (Sender as TMenuItem).Caption;
  Editor.Lines. LoadFromFile(CurrentFile);
....

Bryan Dayton

"Wayne & Carr" <del...@carrz-fox-fire.com> wrote in message
news:3c7ac882_2@dnews...

Quote
> Sorry for the back to back posting, even though they are different topics.
> Just do not like posting like this anymore.
> Just have to sometimes, when you are at your wits end.

> Thank You

> _____now question and hopefully someone with an answer_______

>   Hello all;
> I have ran into a slight dilemma.

>    I am loading files into the editor by use of the

> procedure TForm1.MenuItem1.Click(Sender: TObject);
> begin
> Editor.lines. LoadFromFile('file1.dat');
> end

> procedure TForm1.MenuItem2.Click(Sender: TObject);
> and so on, and so on, and so on, and so on, and so on!

> procedure TForm1.FormClose(Sender: TObject);
> begin
> Editor.lines. SaveToFile('file1.dat');
> //  their are 144-files listed just like this.
> end

> But this is causing a major problem though.

>   Their are currently 144 .dat files that you can choose to load into the
> editor. By use of PopupMenu items.
> . When closing I have each file in the OnClose event,
> So their are 144 files listed in the OnClose Event.

>   I need a way to save the files when you close the program, without any
> user interaction what so ever.
> This is the unique interface that I want for this version of the software.

>   Is their another means of saving the files that will not cause them to
> over ride each other
> when the form closes.

>   I am going to go and try a few things now, But please any suggestions on
> this matter will be very grateful.
> Thank you

> Wayne

Re:Save File OnClose, Save information to all files??


  Thank you Bryan;
For your response.

Quote
> Perhaps something like this (assumes each menu item caption is the name of
a
> file)....

> ...OnMenuItem.Click...
> var CurrentFile : TFileName;
> begin
>   CurrentFile := (Sender as TMenuItem).Caption;
>   Editor.Lines. LoadFromFile(CurrentFile);
> ....

> Bryan Dayton

But I do not think that this is what I can use, unfortunately!!!!.

  This is what it looks like exactly:
----------1st code in PopupMenuItem---------------
procedure TSecondaryForm.Music1Click(Sender: TObject);
begin
  Editor.Lines.LoadFromFile('Data-Files\Ent-Music.dat');
end;
----------------------------------------------------

-----This is what my OnClose event looks like exactly--------
procedure TSecondaryForm.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
  Editor.Lines.SaveToFile('Data-Files\Ent-Music.dat');
  Editor.Lines.SaveToFile('Data-Files\Ent-Film.dat');
  Editor.Lines.SaveToFile('Data-Files\Ent-Broadway.dat');
end;
------------------------------------

This is the 1st Menu Item that you come too. In the PopupMenu.
I need it to open each one of these files individually without hesitation.
Using the method that you provided will not work !
I need it to open the files that are located in the directory.
by name. like the actual file in the code above. It is called to open
the directory   =  Data-Files
the file            =  Ent-Music.dat
 Let the user edit that file (either deleting information or adding in new
information)
and then when they close that file it then saves it, and allows then to open
another file
in the PopupMenu and do the same routine.

   With the code above, it works great, but it only effects the others files
when you either close the window.
  See their is no SaveDialog or OpenDialog on the form, This is totally a
100% non user interaction
part of the application. The only thing that the user has to do, is just add
or delete information
in the file (s) and then go about working in the main part of the
application, It is fast and more efficient
and a much better user interface than having to worry about clicking a
button to save the file
every time that you are thru with it, You can just open another file and
keep on trucking.

  I hope that this makes sense and that someone can then tell me what I can
do.

------------Added after testing something-----------
I wanted to try a few things before re-sponding to Bryans post.
I went in and found out that when you Load the .dat file into the editor
and you have finished editing it, and you then wanted to go into another
file and do some
work in it, that it would not save the information automatically.?? This is
a MAJOR Problem.
So I tested it to see if I could make it save when you have finished editing
the .dat file all from the menuitem
but it does not work, Though if it would have worked, this could have
possibly solved my dilemma.

-----This is the code that I tried---------
procedure TSecondaryForm.Music1Click(Sender: TObject);
begin
 Editor.Lines.LoadFromFile('Data-Files\Ent-Music.dat');
if fileexists ('Data-Files\Ent-Music.dat') then begin
 Editor.Lines.SaveToFile('Data-Files\Ent-Music.dat');
end; end;
-----End of trying-----------

  as you see, if this would have worked then their would be no need for the
OnClose event
to even exist in the program. It would all be done from here.

-----------

Well that is enough for this book :~)

  Can someone please help in this, and Bryan if you may have any idea that
will make this
work, I would gratefully appreciate you affords again.

  Thank you to anyone that can help.

Wayne

Re:Save File OnClose, Save information to all files??


  Can anyone help on this issue??
Please

Wayne

"Wayne & Carr" <del...@carrz-fox-fire.com> wrote in message
news:3c7ac882_2@dnews...

Quote
> Sorry for the back to back posting, even though they are different topics.
> Just do not like posting like this anymore.
> Just have to sometimes, when you are at your wits end.

> Thank You

> _____now question and hopefully someone with an answer_______

>   Hello all;
> I have ran into a slight dilemma.

>    I am loading files into the editor by use of the

> procedure TForm1.MenuItem1.Click(Sender: TObject);
> begin
> Editor.lines. LoadFromFile('file1.dat');
> end

> procedure TForm1.MenuItem2.Click(Sender: TObject);
> and so on, and so on, and so on, and so on, and so on!

> procedure TForm1.FormClose(Sender: TObject);
> begin
> Editor.lines. SaveToFile('file1.dat');
> //  their are 144-files listed just like this.
> end

> But this is causing a major problem though.

>   Their are currently 144 .dat files that you can choose to load into the
> editor. By use of PopupMenu items.
> . When closing I have each file in the OnClose event,
> So their are 144 files listed in the OnClose Event.

>   I need a way to save the files when you close the program, without any
> user interaction what so ever.
> This is the unique interface that I want for this version of the software.

>   Is their another means of saving the files that will not cause them to
> over ride each other
> when the form closes.

>   I am going to go and try a few things now, But please any suggestions on
> this matter will be very grateful.
> Thank you

> Wayne

Re:Save File OnClose, Save information to all files??


I'm not complete sure what you want.. somehow i get the feeling you want to
save a file on a certain point within your program but you don't know the
name?!?

You could make a pointer to a string that contains the name and save this
pointer
in the tag attribute from your menuitem or richedit component. Now you have
several
options:
- When you load another file, in the routine you load the file you can check
the tag
if there is a value (if there is you can save the data first)
- When your application quit you can go trough the component list of your
form for
each component that has a tag with a filename on it save it.

Maby this helps...

Kind regards,

Peter van Wijhe

"Wayne & Carr" <del...@carrz-fox-fire.com> schreef in bericht
news:3c7b4402_1@dnews...

Quote
>   Thank you Bryan;
> For your response.
> > Perhaps something like this (assumes each menu item caption is the name
of
> a
> > file)....

> > ...OnMenuItem.Click...
> > var CurrentFile : TFileName;
> > begin
> >   CurrentFile := (Sender as TMenuItem).Caption;
> >   Editor.Lines. LoadFromFile(CurrentFile);
> > ....

> > Bryan Dayton

> But I do not think that this is what I can use, unfortunately!!!!.

>   This is what it looks like exactly:
> ----------1st code in PopupMenuItem---------------
> procedure TSecondaryForm.Music1Click(Sender: TObject);
> begin
>   Editor.Lines.LoadFromFile('Data-Files\Ent-Music.dat');
> end;
> ----------------------------------------------------

> -----This is what my OnClose event looks like exactly--------
> procedure TSecondaryForm.FormClose(Sender: TObject;
>   var Action: TCloseAction);
> begin
>   Editor.Lines.SaveToFile('Data-Files\Ent-Music.dat');
>   Editor.Lines.SaveToFile('Data-Files\Ent-Film.dat');
>   Editor.Lines.SaveToFile('Data-Files\Ent-Broadway.dat');
> end;
> ------------------------------------

> This is the 1st Menu Item that you come too. In the PopupMenu.
> I need it to open each one of these files individually without hesitation.
> Using the method that you provided will not work !
> I need it to open the files that are located in the directory.
> by name. like the actual file in the code above. It is called to open
> the directory   =  Data-Files
> the file            =  Ent-Music.dat
>  Let the user edit that file (either deleting information or adding in new
> information)
> and then when they close that file it then saves it, and allows then to
open
> another file
> in the PopupMenu and do the same routine.

>    With the code above, it works great, but it only effects the others
files
> when you either close the window.
>   See their is no SaveDialog or OpenDialog on the form, This is totally a
> 100% non user interaction
> part of the application. The only thing that the user has to do, is just
add
> or delete information
> in the file (s) and then go about working in the main part of the
> application, It is fast and more efficient
> and a much better user interface than having to worry about clicking a
> button to save the file
> every time that you are thru with it, You can just open another file and
> keep on trucking.

>   I hope that this makes sense and that someone can then tell me what I
can
> do.

> ------------Added after testing something-----------
> I wanted to try a few things before re-sponding to Bryans post.
> I went in and found out that when you Load the .dat file into the editor
> and you have finished editing it, and you then wanted to go into another
> file and do some
> work in it, that it would not save the information automatically.?? This
is
> a MAJOR Problem.
> So I tested it to see if I could make it save when you have finished
editing
> the .dat file all from the menuitem
> but it does not work, Though if it would have worked, this could have
> possibly solved my dilemma.

> -----This is the code that I tried---------
> procedure TSecondaryForm.Music1Click(Sender: TObject);
> begin
>  Editor.Lines.LoadFromFile('Data-Files\Ent-Music.dat');
> if fileexists ('Data-Files\Ent-Music.dat') then begin
>  Editor.Lines.SaveToFile('Data-Files\Ent-Music.dat');
> end; end;
> -----End of trying-----------

>   as you see, if this would have worked then their would be no need for
the
> OnClose event
> to even exist in the program. It would all be done from here.

> -----------

> Well that is enough for this book :~)

>   Can someone please help in this, and Bryan if you may have any idea that
> will make this
> work, I would gratefully appreciate you affords again.

>   Thank you to anyone that can help.

> Wayne

Re:Save File OnClose, Save information to all files??


you could try creating a collection that holds info on each file such
as name, location, contents, etc... then set the menuitem tags to the
index of the file in the collection, when the user selects an item
from the menu the onclick event could lookup the file in the
collection and load its contents into a property of the collection
item.  When your program exits you could loop through the collection
and save the modified files.

Re:Save File OnClose, Save information to all files??


 Thank You Michael;

  That is quite similar to what I had to do.

Thank you

Wayne

Quote
"Michael" <d...@bother.net> wrote in message

news:3c83e860.1369439@forums.borland.com...
Quote
> you could try creating a collection that holds info on each file such
> as name, location, contents, etc... then set the menuitem tags to the
> index of the file in the collection, when the user selects an item
> from the menu the onclick event could lookup the file in the
> collection and load its contents into a property of the collection
> item.  When your program exits you could loop through the collection
> and save the modified files.

Other Threads