Delphi Memo的记事本功能


unit Unit1; interface uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.ExtDlgs; type
TForm1 = class(TForm)
Memo1: TMemo;
FileOpen: TButton;
FileSave: TButton;
FileSaveAs: TButton;
FileExit: TButton;
FileNew: TButton;
OpenDialog1: TOpenDialog;
SaveDialog1: TSaveDialog;
procedure FileOpenClick(Sender: TObject);
procedure FileSaveClick(Sender: TObject);
procedure FileExitClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FileNewClick(Sender: TObject);
procedure FileSaveAsClick(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
{ Private declarations }
FFileName: string;
FUpdating: Boolean;
FDragOfs: Integer;
FDragging: Boolean;
procedure CheckFileSave;
procedure SetFileName(const FileName: String);
procedure PerformFileOpen(const AFileName: string);
procedure WMDropFiles(var Msg: TWMDropFiles); message WM_DROPFILES;
public
{ Public declarations }
end; var
Form1: TForm1; implementation uses ShellAPI;
{$R *.dfm} resourcestring
sSaveChanges = '是否将未更改保存到 %s?';
sOverWrite = '%s 已存在。'+#13#10+'要替换它吗?';
sTitle = '记事本';
sUntitled = '未命名';
sColRowInfo = 'Line: %3d Col: %3d';
sCommonDlgFileName = '文本文档(*.txt)|*.txt|所有文件(*.*)|*.*'; procedure TForm1.CheckFileSave;
var
SaveRespond: Integer;
begin
if not Memo1.Modified then
Exit;
SaveRespond := MessageBox(Handle, PWideChar(Format(sSaveChanges, [FFileName])
), PWideChar(sTitle), MB_YESNOCANCEL + MB_ICONINFORMATION);
case SaveRespond of
idYes:
FileSave.click;
idNo:
; { Nothing }
idCancel:
Abort;
end;
end; procedure TForm1.SetFileName(const FileName: String);
begin
FFileName := FileName;
Caption := Format('%s - %s', [ExtractFileName(FileName), sTitle]);
end; procedure TForm1.PerformFileOpen(const AFileName: string);
begin
Memo1.Lines.LoadFromFile(AFileName);
SetFileName(AFileName);
Memo1.SetFocus;
Memo1.Modified := False;
end; procedure TForm1.WMDropFiles(var Msg: TWMDropFiles);
var
CFileName: array [0 .. MAX_PATH] of Char;
begin
try
if DragQueryFile(Msg.Drop, 0, CFileName, MAX_PATH) > 0 then
begin
CheckFileSave;
PerformFileOpen(CFileName);
Msg.Result := 0;
end;
finally
DragFinish(Msg.Drop);
end;
end; procedure TForm1.FileNewClick(Sender: TObject);
begin
CheckFileSave;
SetFileName(sUntitled); Memo1.Lines.Clear;
Memo1.Modified := False;
end; procedure TForm1.FileOpenClick(Sender: TObject);
begin
CheckFileSave; with TOpenDialog.Create(nil) do
begin
Filter := sCommonDlgFileName;
FileName:='*.txt';
if Execute then
begin
PerformFileOpen(FileName);
Memo1.ReadOnly := ofReadOnly in Options;
end;
end;
end; procedure TForm1.FileSaveAsClick(Sender: TObject);
begin
with TSaveDialog.Create(nil) do
begin
Filter := sCommonDlgFileName;
FileName:='*.txt';
if Execute then
begin
if FileExists(FileName) then
if MessageBox(Handle, PWideChar(Format(sOverWrite, [FFileName])),
PWideChar(sTitle), MB_YESNOCANCEL + MB_ICONINFORMATION) <> idYes then
Exit;
Memo1.Lines.SaveToFile(FileName);
SetFileName(FileName);
Memo1.Modified := False;
end;
end;
end; procedure TForm1.FileSaveClick(Sender: TObject);
begin
if FFileName = sUntitled then
FileSaveAs.click
else
begin
Memo1.Lines.SaveToFile(FFileName);
Memo1.Modified := False;
end;
end; procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
CheckFileSave;
end; procedure TForm1.FormCreate(Sender: TObject);
begin
SetFileName(sUntitled);
DragAcceptFiles(Handle, True);
end; procedure TForm1.FileExitClick(Sender: TObject);
begin
Close;
end; end.
Delphi Memo的记事本功能的更多相关文章
- 【Android】12.6 利用Intent实现记事本功能(NotePad)
分类:C#.Android.VS2015: 创建日期:2016-02-23 一.简介 这个例子演示如何实现一个简单的记事本功能. 该例子提前使用了后面章节将要介绍的SQLLite数据库. 二.示例-c ...
- JAVA 运用流编程实现简单的"记事本"功能
一.概要 1.功能介绍 2.实现的思路及步骤代码 3.完整代码 二.功能 运用IO流和Swing实现简单的记事本功能(打开.保存.退出) 三.思路及实现步骤 1.在构造函数中画出操作界面 //创建jt ...
- delphi实现窗体闪烁功能
delphi实现窗体闪烁功能 以前做窗口闪动时都没有考虑到让任务栏上的按钮闪动的问题, 现在一个客户需要任务栏按钮闪动,发现以前使用的flashwindow不能达到要求了, 查找了一下,找到flash ...
- delphi 10.2 ----memo 的例子 实现基本记事本功能
unit Unit2; interface uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System ...
- 教程-Delphi 调用控制面板设置功能
应用程序运行时,有时需要对系统环境有特殊要求.例如,在Delphi数据库应用程序中可能需要进行BDE(Borland Database Engine)或ODBC数据源名称(DSN:Data Sourc ...
- 使用jquery.mobile和WebSQL实现记事本功能
1.记事本列表页 1.1.页面结构与样式: <div data-role="page" id="home"> <div data-role=& ...
- [教学] Delphi IDE 文件搜寻功能
Delphi IDE 提供了一个方便的文件搜寻功能,操作如下: 点 Search 选单内的 Find in Files... 例如我们想搜寻 JFile 需要引用那一个源码,可输入如下: 输入关键字: ...
- 第十四周课程总结&记事本功能的简单实现。
(1)课程总结: 这周简单学习了下JDBC的内容: JDBC API 允许用户访问任何形式的表格数据,尤其是存储在关系数据库中的数据. 执行流程: (1)连接数据源,如:数据库. (2)为数据库传递查 ...
- [原创] delphi Memo 滚动到底部/开始 [Delphi XE、Delphi 7]
以前控制Memo滚动到底部的操作: SendMessage(memo1.Handle,WM_VSCROLL,SB_BOTTOM,0); 或者 Memo1.SelLength:=Length(Memo1 ...
随机推荐
- div section article aside的理解
div 是一个大的容器 内部可以包含header main nav aside footer等标签 没有语义,多用于为脚本添加样式 section的语义比div语义强些,用于主题性比较强的内容,比如一 ...
- Apache 支持.htaccess
******************************************************************************* Apache 服务器 ********* ...
- WCF SOAP
WCF SOAP服务端解析 ASP.NET Core中间件(Middleware)进阶学习实现SOAP 解析. 本篇将介绍实现ASP.NET Core SOAP服务端解析,而不是ASP.NET Cor ...
- ARC - MRC
1. 选择工程 ---> build phases --> .m中添加 -fno-objc-arc
- asp.net学习
http://www.cnblogs.com/fish-li/archive/2011/12/27/2304063.html
- 写个自动下载安装Ant的shell脚本【一】
#!/bin/bash ###################################################### # file name: install_ant.sh # # f ...
- BZOJ 3083 遥远的国度 树链剖分
3083: 遥远的国度 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 797 Solved: 181[Submit][Status] Descrip ...
- BZOJ 3992 序列统计
Description 小C有一个集合\(S\),里面的元素都是小于\(M\)的非负整数.他用程序编写了一个数列生成器,可以生成一个长度为\(N\)的数列,数列中的每个数都属于集合\(S\). 小C用 ...
- Delphi实现HTMLWebBrowser实现HTML界面
HTML的界面有以下特点:图文混排,格式灵活,可以包含Flash.声音和视频等,实现图文声像的多媒体界面,而且易于建立和维护.另外,HTML的显示环境一般机器上都具备,通常不需要安装额外的软件.当然, ...
- 3.2 java中堆栈(stack)和堆(heap)(还在问静态变量放哪里,局部变量放哪里,静态区在哪里.....进来)
(1)内存分配的策略 按照编译原理的观点,程序运行时的内存分配有三种策略,分别是静态的,栈式的,和堆式的. 静态存储分配是指在编译时就能确定每个数据目标在运行时刻的存储空间需求,因而在编 译时就可以给 ...