For Newbie

Tuesday, 15 November 2011

String Saved to File on Delphi


Tricks to save the existing string in memory into a text file.

Declaration procedure:
StrKeFile procedure (nmFile: TFileName; strTeks: String);
var
   Streamer: TFileStream;
begin
   Streamer: = TFileStream.Create (nmFile, fmCreate);
   try
     Streamer.WriteBuffer (strTeks [1], Length (strTeks));
   finally
     Streamer.Free;
   end;
end;

Example of implementation:
procedure TForm1.Button1Click (Sender: TObject);
inpStr var: String;
begin
   inpStr: = Edit1.Text;
   StrKeFile ('C: \ tes.txt', Edit1.Text);
end;

Example # 2 (using TSaveDialog):
procedure TForm1.Button1Click (Sender: TObject);
begin
   if SaveDialog1.Execute then
   begin
     StrKeFile (SaveDialog1.FileName, Edit1.Text);
   end;
end;

Share on Facebook
Share on Twitter
Share on Google+

Related : String Saved to File on Delphi