procedure TRandForm.CheckFileSave;
var
SaveResp: Integer;
begin
if not ClueMemo.Modified then Exit;
SaveResp := MessageDlg(Format('Save changes to %s?', [currFileName]),
mtConfirmation, mbYesNoCancel, 0);
case SaveResp of
idYes: FileSave(Self);
{do nothing if the response is idNo...}
idNo: ;
idCancel: Abort;
end;
end;
procedure TRandForm.FileSave(Sender: TObject);
begin
if currFileName = 'Untitled' then
FileSaveAs(Sender)
else
begin
ClueMemo.Lines.SaveToFile(currFileName);
ClueMemo.Modified := False;
end;
end;
procedure TRandForm.OpenButtonClick(Sender: TObject);
begin
CheckFileSave;
if OpenDialog.Execute then
begin
ClueMemo.Lines.LoadFromFile(OpenDialog.FileName);
SetFileName(OpenDialog.FileName);
ClueMemo.SetFocus;
ClueMemo.Modified := False;
ClueMemo.ReadOnly := ofReadOnly in OpenDialog.Options;
end;
end;
procedure TRandForm.SetFileName(const FileName: String);
begin
currFileName := FileName;
Caption := Format('%s - %s', [ExtractFileName(FileName), Application.Title]);
end;
procedure TRandForm.SaveButtonClick(Sender: TObject);
begin
if currFileName = 'Untitled' then
FileSaveAs(Sender)
else
begin
ClueMemo.Lines.SaveToFile(currFileName);
ClueMemo.Modified := False;
end;
end;
procedure TRandForm.FileSaveAs(Sender: TObject);
begin
if SaveDialog.Execute then
begin
if FileExists(SaveDialog.FileName) then
if MessageDlg(Format('OK to overwrite %s', [SaveDialog.FileName]),
mtConfirmation, mbYesNoCancel, 0) <> idYes then Exit;
ClueMemo.Lines.SaveToFile(SaveDialog.FileName);
SetFileName(SaveDialog.FileName);
ClueMemo.Modified := False;
end;
end;