Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Look if the file is modified.

Posted on 2006-10-29
5
Medium Priority
?
178 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

721 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