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 ...
随机推荐
- OSI参考模型 VS TCP/IP参考模
OSI参考模型 VS TCP/IP参考模 TCP/IP各层对应的协议 TCP/IP的层 对应的TCP/IP协议 ...
- #Leet Code# Root to leaf
语言:Python 描述:使用递归实现 def getList(self, node): if node is None: return [] if node.left is None and nod ...
- smali 语法基础
dalvik字节码有两种类型,原始类型和引用类型.对象和数组是引用类型,其它都是原始类型. V void Z boolean B byte S short C char I int F ...
- java入门(与C++的不同之处)封装篇
初学java,总是想将它与之前的C++做比较,看了慕客网的java入门视频,一直觉得在面向对象方面,它和C++有太多相同的地方,结果今天学到了两点不同之处,现在将它记录下来: 1. java的访问修 ...
- initWithCoder: 与initWithFrame:
之前一直用代码来编写画面,现在着手使用storyboard和xib来构筑画面,遇到initWithCoder方法, 故查了下,initWithCoder方法的调用,看了篇博客,链接如下: http:/ ...
- Python on Android
Python on Android Posted on April 29, 2015 by Alexander Taylor There are an increasing number of r ...
- 安卓天天练练(三)常用组件Toast
要写几句java package com.narumi.android_7_2; import android.app.Activity; import android.os.Bundle; impo ...
- jquery.lazyload的使用
1.引入 <script src="jquery.js" type="text/javascript"></script> <sc ...
- python读取文件通过正则过滤需要信息然后保存到新文件里
import osimport reimport fileinput def getDataFromFile(): rt = "/(.*)/(.*).apk" ...
- bzoj1334
..] of boolean; a:..] of longint; i,n,s,j,ans:longint; procedure sort(l,r: longint); var i ...