Solved

Look if the file is modified.

Posted on 2006-10-29
5
170 Views
Last Modified: 2010-04-05
Dear Experts,

In my previous question I have asked how to implement Save and SaveAs, I have
got a good solution, in that question Bobi100 gave me a good advice. This is what
he said:

"one more thing that would improve your application is an isModified flag, try adding a boolean property in your form, make sure this flag is set to False on create, after a successful save, after new, and after opening. Set it to True on any change done to whatever input you have in your form, then, wrap the case statement statement in the code above with this:"

  if IsModified then
    case ...................
  else
    LoadOptions(CfgFile); //load the default file automatically because the file was not modified

Only I don’t know how to implement his advice !
This code below is what I got sofar. Can someone help me?


(*-----------------------------------------------*)
procedure TMainForm.Open1Click(Sender: TObject);
begin
  if socOpen then Warning2
  else begin
    OpenDialog1.InitialDir := ExtractFileDir(Application.exename) + '\Sessions\';
    OpenDialog1.DefaultExt := 'emu';
    if OpenDialog1.Execute then
    begin
      LoadOptions(OpenDialog1.Filename);
      CurrentFile := OpenDialog1.FileName;
      MakeConnect;
    end;
  end;
end;
(*-----------------------------------------------*)
procedure TMainForm.New1Click(Sender: TObject);
begin
  if socOpen then Warning1
  else Connect1Click(sender);
end;
(*-----------------------------------------------*)
procedure TMainForm.Save1Click(Sender: TObject);
begin
  if (CurrentFile = CfgFile) then
    SaveAs1Click(sender)
  else
    SaveOptions(CurrentFile)
end;
(*-----------------------------------------------*)
procedure TMainForm.SaveAs1Click(Sender: TObject);
begin
  SaveDialog1.InitialDir := ExtractFileDir(Application.exename) + '\Sessions\';
  SaveDialog1.DefaultExt := 'emu';
  if SaveDialog1.Execute then
  begin
    if SaveDialog1.Filename <> CfgFile then
    begin
      SaveOptions(SaveDialog1.Filename);
      CurrentFile := SaveDialog1.Filename;
    end
    else
      ShowMessage('Can''t write to default file');
  end;
end;
(*-----------------------------------------------*)


Greetings,

Peter Kiers
0
Comment
Question by:peterkiers
  • 3
  • 2
5 Comments
 
LVL 19

Expert Comment

by:MerijnB
ID: 17832232
I don't really know what you are making here, but it seems like you'll have to use the IsModified flag in your SaveOptions() routine:

procedure TMainForm.SaveOptions(FileName: string);
begin
 if IsModified then   // only save if options are modified
 begin
  // do your saving stuff here
 end;
end;

This means, like Bobi100 said you'll have to set IsModified to false whenever you save, open or make a new file and to true.
This is surely a nice addition, but if saving the options doesn't take long you might want to just always save and don't use this extra boolean.
0
 
LVL 1

Author Comment

by:peterkiers
ID: 17832579
Maybe we should take this step bij step, because I don't follow anymore...
and I am trying and trying but no results.

The procedure New1Click should first look if the file that is loaded
hasn't been changed.

If so then show message:  'Do you want to save the current file?'

if user clicks Yes then        
                                    Save1Click(Sender); //do a save or save as
                                     LoadOptions(CfgFile); //load the default file
if user clicks No then
                                   mrNo: LoadOptions(CfgFile); //load the default file
                                    mrCancel: ;//do nothing
 
Then if the user clicks YES or NO on the message
The second message has to appear, to determine if there is a connection
if so show warning else Connect1Click:

 if socOpen then Warning1     //if socopen is true then showmessage
 else Connect1Click(sender);  //else show message connect1click


I am trying to write that, this is the totally wrong code:

procedure TMainForm.New1Click(Sender: TObject);
begin
  if socOpen then Warning1
  else Connect1Click(sender);

  begin
  case MessageDlg('Do you want to save the current file?', mtConfirmation,
                  [mbYes, mbNo, mbCancel],0) of
    mrYes:
    begin
      Save1Click(Sender); //do a save or save as
      LoadOptions(CfgFile); //load the default file
    end;
    mrNo: LoadOptions(CfgFile); //load the default file
    mrCancel: ;//do nothing
  end
end;
end;

Peter
0
 
LVL 19

Accepted Solution

by:
MerijnB earned 500 total points
ID: 17832634
I think you have the questions you want to ask the user and the actions you want to take to those answers not correct.
Can you try to explain what you want in words, not in code, because I think the pieces like:

                                    Save1Click(Sender); //do a save or save as
                                     LoadOptions(CfgFile); //load the default file

and

                                   mrNo: LoadOptions(CfgFile); //load the default file
                                    mrCancel: ;//do nothing

will not do what you think they should do.
0
 
LVL 1

Author Comment

by:peterkiers
ID: 17832802
Oke, this isn't going wright, so I try another approach.

I have a little other problem, maybe you could help me with that
and forget the rest, and then the 500 points are all yours.

I want the file CfgFile to be loaded when the programm startsup
and when the user clicks on the toolbutton New.

I have allready the code to start the file at the startup of the programm:

  CfgFile := IncludeTrailingBackslash(ExeDir) + 'Emu3270.emr';
  CurrentFile := CfgFile;
  if LoadOptions(CfgFile) then
    ShowMessage('Warning: Errors found in config file: ' + CfgFile);

But the New-button doesn't reload the CfgFile.

This is what I got.

procedure TMainForm.New1Click(Sender: TObject);
begin
  if socOpen then Warning1                  //if there is a connection show message
  else Connect1Click(sender);               //else start form Connect.
end;

procedure TMainForm.Warning1;
begin
  if (Application.MessageBox(
    'You must disconnect before opening another connection.' + #10 + #13 +
    'Do you want to disconnect?',
    'Access2All',
    MB_YESNO + MB_DEFBUTTON1 + MB_ICONEXCLAMATION) = ID_YES) then
    begin
    Disconnect1Click(self);
    Connect1click(self);
    end;
end;

The code to save to file is : SaveOptions(CfgFile);
to code to load the file is : LoadOptions(CfgFile);

Peter





 



the programm
has to look if the file that's is loaded has been changed
if so
0
 
LVL 1

Author Comment

by:peterkiers
ID: 17833143
I give up
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now