📄 child.pas
字号:
unit Child;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Menus, StdCtrls, ComCtrls, IniFiles;
type
TfrmChild = class(TForm)
RichEdit1: TRichEdit;
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure RichEdit1Change(Sender: TObject);
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
procedure FormActivate(Sender: TObject);
private
FIsModified: Boolean;
FIsNamed: Boolean;
FFileName: String;
procedure SetIsModified(const Value: Boolean);
procedure SetIsNamed(const Value: Boolean);
procedure SetFileName(const Value: String);
{ Private declarations }
public
constructor Create(Owner:TComponent);override;
property IsModified:Boolean read FIsModified write SetIsModified;
property IsNamed:Boolean read FIsNamed write SetIsNamed;
property FileName:String read FFileName write SetFileName;
procedure LoadFromFile(AFileName:String);
procedure SaveToFile(AFileName:String);
end;
var
frmChild: TfrmChild;
implementation
uses Main;
{$R *.dfm}
constructor TfrmChild.Create(Owner: TComponent);
begin
inherited;
FIsModified := False;
FIsNamed := False;
FFileName := '';
end;
procedure TfrmChild.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Action := caFree;
end;
procedure TfrmChild.LoadFromFile(AFileName: String);
begin
RichEdit1.Lines.LoadFromFile(AFileName);
IsNamed := True;
FileName := AFileName;
Caption := AFileName;
IsModified := False;
end;
procedure TfrmChild.SaveToFile(AFileName: String);
begin
IsNamed := True;
FileName := AFileName;
RichEdit1.Lines.SaveToFile(AFileName);
IsModified := False;
end;
procedure TfrmChild.SetFileName(const Value: String);
begin
FFileName := Value;
Caption := Value;
end;
procedure TfrmChild.SetIsModified(const Value: Boolean);
begin
FIsModified := Value;
end;
procedure TfrmChild.SetIsNamed(const Value: Boolean);
begin
FIsNamed := Value;
end;
procedure TfrmChild.RichEdit1Change(Sender: TObject);
begin
IsModified := True;
frmMain.UpdateStatusBar;
end;
procedure TfrmChild.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
var
res : Word;
begin
if IsModified then
begin
res := MessageDlg('File '+FileName+' was modified. Save it now?',
mtWarning, [mbYes,mbNo,mbCancel], 0);
case res of
mrYes:
begin
RichEdit1.Lines.SaveToFile(FileName);
CanClose := True;
end;
mrNo:
CanClose := True;
mrCancel:
CanClose := False;
end;
end
else
CanClose := True;
end;
procedure TfrmChild.FormActivate(Sender: TObject);
begin
frmMain.UpdateStatusBar;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -