Solved

Look if the file is modified.

Posted on 2006-10-29
5
171 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

911 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

20 Experts available now in Live!

Get 1:1 Help Now