Delphi Memo的记事本功能
 
 
 

 
 
这个代码实现了Windows记事本的主要功能。
新建,打开,保存,另存,退出。
文件拖拽打开文件 这主要是判断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的记事本功能的更多相关文章

  1. 【Android】12.6 利用Intent实现记事本功能(NotePad)

    分类:C#.Android.VS2015: 创建日期:2016-02-23 一.简介 这个例子演示如何实现一个简单的记事本功能. 该例子提前使用了后面章节将要介绍的SQLLite数据库. 二.示例-c ...

  2. JAVA 运用流编程实现简单的"记事本"功能

    一.概要 1.功能介绍 2.实现的思路及步骤代码 3.完整代码 二.功能 运用IO流和Swing实现简单的记事本功能(打开.保存.退出) 三.思路及实现步骤 1.在构造函数中画出操作界面 //创建jt ...

  3. delphi实现窗体闪烁功能

    delphi实现窗体闪烁功能 以前做窗口闪动时都没有考虑到让任务栏上的按钮闪动的问题, 现在一个客户需要任务栏按钮闪动,发现以前使用的flashwindow不能达到要求了, 查找了一下,找到flash ...

  4. delphi 10.2 ----memo 的例子 实现基本记事本功能

    unit Unit2; interface uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System ...

  5. 教程-Delphi 调用控制面板设置功能

    应用程序运行时,有时需要对系统环境有特殊要求.例如,在Delphi数据库应用程序中可能需要进行BDE(Borland Database Engine)或ODBC数据源名称(DSN:Data Sourc ...

  6. 使用jquery.mobile和WebSQL实现记事本功能

    1.记事本列表页 1.1.页面结构与样式: <div data-role="page" id="home"> <div data-role=& ...

  7. [教学] Delphi IDE 文件搜寻功能

    Delphi IDE 提供了一个方便的文件搜寻功能,操作如下: 点 Search 选单内的 Find in Files... 例如我们想搜寻 JFile 需要引用那一个源码,可输入如下: 输入关键字: ...

  8. 第十四周课程总结&记事本功能的简单实现。

    (1)课程总结: 这周简单学习了下JDBC的内容: JDBC API 允许用户访问任何形式的表格数据,尤其是存储在关系数据库中的数据. 执行流程: (1)连接数据源,如:数据库. (2)为数据库传递查 ...

  9. [原创] delphi Memo 滚动到底部/开始 [Delphi XE、Delphi 7]

    以前控制Memo滚动到底部的操作: SendMessage(memo1.Handle,WM_VSCROLL,SB_BOTTOM,0); 或者 Memo1.SelLength:=Length(Memo1 ...

随机推荐

  1. sass学习--什么是sass

    1.预备知识--什么是 CSS 预处理器 CSS 预处理器定义了一种新的语言,其基本思想是,用一种专门的编程语言,为 CSS 增加了一些编程的特性,将 CSS 作为目标生成文件,然后开发者就只要使用这 ...

  2. 关于js的callback回调函数的理解

    回调函数的处理逻辑理解:所谓的回调函数处理逻辑,其实就是先将回调函数的代码 冻结(或者理解为闲置),接着将这个回调函数的代码放到回调函数管理器的队列里面. 待回调函数被触发调用的时候,对应的回调函数的 ...

  3. shell 常用

    /etc/password      用户的 home路径设置 chwon  groupname:username    path_or_file  -R    # 修改文件左右者 chomd

  4. 简单学C——第五天

    结构体 首先明确,结构体是一种构造的数据类型,是一种由多个数据类型如 int,char,double,数组或者结构体......组成的类型,现在告诉大家如何定义一个结构体.在定义int整型变量时,大家 ...

  5. Linux下的echo服务器

    epoll模式下的echo服务器,忘记从哪个网页上粘贴过来的了,学习一下 /* * main.cc * * Created on: 2009-11-30 * Author: liheyuan * De ...

  6. webkit.net使用方法日记

    1.首先貌似只有36位的库,所以项目也要修改为X86平台 2.里面的所有dll库文件都要拷贝到项目中去,包括WebKitBrowser.dll.manifest  此文件一定要拷贝过去. 3.然后引用 ...

  7. MVC3的一个意外的异常 String was not recognized as a valid Boolean. @using (Html.BeginForm())

    客户的网站放在一个虚拟空间,之间都没有修改过程序.可是网站的后台登录页面报错  String was not recognized as a valid Boolean. ,错误指向@using (H ...

  8. java程序编译

    Empoyee.java package Company; public class Empoyee { String name = ""; public Empoyee(Stri ...

  9. www.nygwkt.com

    南京宁阳制冷设备维修有限公司是专业从事厨房空调,http://www.nygwkt.com岗位空调制冷设备设计.制造.安装.改造.维修.保养的专业化公司.在南京享有很高的客户评论. 我们对南京宁阳制冷 ...

  10. [BZOJ 3129] [Sdoi2013] 方程 【容斥+组合数取模+中国剩余定理】

    题目链接:BZOJ - 3129 题目分析 使用隔板法的思想,如果没有任何限制条件,那么方案数就是 C(m - 1, n - 1). 如果有一个限制条件是 xi >= Ai ,那么我们就可以将 ...