Board index » delphi » Code For: Open/Save/Save As (*.ini format)

Code For: Open/Save/Save As (*.ini format)

I'm working on a project with my thesis advisor.
We want to open, save(as) a file into *.ini format using 4 TMemo
windows. Can't find or fabricate what I need. Anyone have some spare
code?

procedure form.FileOpenClick(Sender: TObject);
begin
        ?
end;
procedure form.FileSaveClick(Sender: TObject);
begin
        ?
end;
procedure form.FileSaveAsClick(Sender: TObject);
begin
        ?
end;

Thanks

Nat

--------------------------------------------
Nathalie Lechene
Facult des lettres et sciences humaines
Universit de Sherbrooke

 

Re:Code For: Open/Save/Save As (*.ini format)


Quote
> Why would you want to use 4 TMemos?
> Charles Johnson

A it's a project where a user enters text and after with a submit button
a web page will be created based on this info.

Re:Code For: Open/Save/Save As (*.ini format)


In article <35E5A759.4...@NOSPAMM.ntic.qc.ca>, Natalie

Quote
<lech...@NOSPAMM.ntic.qc.ca> writes:
>We want to open, save(as) a file into *.ini format using 4 TMemo
>windows.

Natalie,

Why would you want to use 4 TMemos?

Charles Johnson

Re:Code For: Open/Save/Save As (*.ini format)


In article <35E5A759.4...@NOSPAMM.ntic.qc.ca>, Natalie
<lech...@NOSPAMM.ntic.qc.ca> writes

Quote
>I'm working on a project with my thesis advisor.
>We want to open, save(as) a file into *.ini format using 4 TMemo
>windows. Can't find or fabricate what I need. Anyone have some spare
>code?

There are many ways - here are some ideas:

type
  form = class(TForm)
    OpenDialog : TOpenDialog;
    SaveDialog : TSaveDialog; //drop these on the form
    :
  private
    FFileName : string;
    FModified : boolean;
  end;

{
You'll need stuff like this too:

FormCreate : FFilename := '';
             FModified := False;

FileNewClick : FFilename := '';
               FModified := False;

Memo1Change: FModified := True;

Quote
}

procedure form.FileOpenClick(Sender: TObject);
var
  IniFile : TIniFile;
begin
  if FModified then
    if MessageBox(Handle, 'Save changes?', PChar(Application.Title),
                  MB_ICONQUESTION or MB_YESNO) = IDYES then
      FileSaveClick(Sender);

  if OpenDialog.Execute then begin
    FFilename := OpenDialog.Filename;

    IniFile := TIniFile.Create(FFilename);

    Memo1.Lines.Add(IniFile.ReadString('Section', 'Ident', 'Default'));

    IniFile.Free;
  end;
end;

procedure form.FileSaveClick(Sender: TObject);
var
  IniFile : TIniFile;
begin
  if FFilename = '' then
    FileSaveAsClick(Sender)
  else begin
    IniFile : TIniFile.Create(FFilename);

    IniFile.WriteString('Section', 'Ident', Memo1.Lines[0]);

    IniFile.Free;
  end;
end;

procedure form.FileSaveAsClick(Sender: TObject);
begin
  if SaveDialog.Execute then begin
    FFilename := SaveDialog.Filename;  

    FileSaveClick(Sender);
  end;
end;

Hope this helps.
--
Jeremy Collins
Kansai Business Systems

Other Threads