D7 tmemo 讀入指定檔案內容跟修改后保存內容 求大神指教
uj5u.com熱心網友回復:
unit Unit1;Button1打開文本檔案。
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Memo1: TMemo;
OpenDialog1: TOpenDialog;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
TextName:string; // 全域變數 保存檔案
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
OpenDialog1.FileName:='';
opendialog1.InitialDir:=sPath;
opendialog1.filter:='文本檔案|*.txt';
if OpenDialog1.Execute then
begin
TextName:=OpenDialog1.FileName;
Memo1.Lines.LoadFromFile(TexxtName); //打開檔案
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
Memo1.Lines.SaveToFile(TexxtName); // 保存檔案
end;
end.
Button2,通過Memo修改文本檔案后,原名保存檔案。
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/78894.html
標籤:語言基礎/算法/系統設計
上一篇:如何判斷點在折線的哪一側
下一篇:We did not find results for: [Fatal Error] osgdrp73.dpk(40): Unit tsPrintGrid wa
