Delphi RxRichEdit高级操作
unit InsertRichEditUnit;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, RichEdit, UHISRichEd;
type
TEditStreamCallBack = function(dwCookie: Longint; pbBuff: PByte; cb: Longint;
var pcb: Longint): DWORD; stdcall;
TEditStream = record
dwCookie: Longint;
dwError: Longint;
pfnCallback: TEditStreamCallBack;
end;
procedure GetRTFSelection(aRichEdit: TUHISRichEdit; IntoStream: TStream);
procedure PutRTFSelection(aRichEdit: TUHISRichEdit; SourceStream: TStream);
procedure InsertRTF(aRichEdit: TUHISRichEdit; S: string);
procedure CopyRTF(aSource, aDest: TUHISRichEdit);
procedure CopyAllRTF(aSource, aDest: TUHISRichEdit);
procedure AppendRTF(aRichEdit: TUHISRichEdit; S: string);
implementation
function EditStreamInCallback(dwCookie: Longint; pbBuff: PByte; cb: Longint;
var pcb: Longint): DWORD; stdcall;
var
TheStream: TStream;
DataAvail: LongInt;
begin
TheStream := TStream(dwCookie);
with TheStream do
begin
DataAvail := Size - Position;
Result := 0;
if DataAvail <= cb then
begin
pcb := Read(pbBuff^, DataAvail);
if pcb <> DataAvail then
result := DWord(E_FAIL);
end
else
begin
pcb := Read(pbBuff^, cb);
if pcb <> cb then
result := DWord(E_FAIL);
end;
end;
TheStream := TStream(dwCookie);
end;
function EditStreamOutCallback(dwCookie: Longint; pbBuff: PByte; cb: Longint;
var pcb: Longint): DWORD; stdcall;
var
TheStream: TStream;
begin
TheStream := TStream(dwCookie);
with TheStream do
begin
if cb > 0 then
pcb := Write(pbBuff^, cb);
Result := 0;
end;
end;
procedure GetRTFSelection(aRichEdit: TUHISRichEdit; IntoStream: TStream);
var
EditStream: TEditStream;
begin
with EditStream do
begin
dwCookie := Longint(IntoStream);
dwError := 0;
pfnCallback := EditStreamOutCallBack;
end;
aRichEdit.Perform(EM_STREAMOUT, SF_RTF or SFF_SELECTION, longint(@EditStream));
end;
procedure PutRTFSelection(aRichEdit: TUHISRichEdit; SourceStream: TStream);
var
EditStream: TEditStream;
begin
with EditStream do
begin
dwCookie := Longint(SourceStream);
dwError := 0;
pfnCallback := EditStreamInCallBack;
end;
aRichEdit.Perform(EM_STREAMIN, SF_RTF or SFF_SELECTION, longint(@EditStream));
end;
procedure InsertRTF(aRichEdit: TUHISRichEdit; S: string);
var
aMemStream: TMemoryStream;
begin
if Length(S) > 0 then
begin
aMemStream := TMemoryStream.Create;
try
aMemStream.Write(S[1], length(S));
aMemStream.Position := 0;
PutRTFSelection(aRichEdit, aMemStream);
finally
aMemStream.Free;
end;
end;
end;
procedure CopyRTF(aSource, aDest: TUHISRichEdit);
var
aMemStream: TMemoryStream;
begin
aMemStream := TMemoryStream.Create;
try
GetRTFSelection(aSource, aMemStream);
aMemStream.Position := 0;
PutRTFSelection(aDest, aMemStream);
finally
aMemStream.Free;
end;
end;
procedure CopyAllRTF(aSource, aDest: TUHISRichEdit);
var
aMemStream: TMemoryStream;
begin
aMemStream := TMemoryStream.Create;
try
aSource.SelectAll;
GetRTFSelection(aSource, aMemStream);
aMemStream.Position := 0;
aDest.SelStart := Length(aDest.Lines.Text);
PutRTFSelection(aDest, aMemStream);
finally
aMemStream.Free;
end;
end;
procedure AppendRTF(aRichEdit: TUHISRichEdit; S: string);
var
Start, Length, EventMask: Integer;
begin
EventMask := SendMessage(aRichEdit.Handle, EM_SETEventMask, 0, 0);
SendMessage(aRichEdit.Handle, WM_SETREDRAW, 0, 0);
Start := aRichEdit.SelStart;
Length := aRichEdit.SelLength;
aRichEdit.SelLength := 0;
aRichEdit.SelStart := System.Length(aRichEdit.Text);
InsertRTF(aRichEdit, s);
aRichEdit.SelStart := Start;
aRichEdit.SelLength := Length;
SendMessage(aRichEdit.Handle, WM_SETREDRAW, 1, 0);
InvalidateRect(aRichEdit.Handle, nil, True);
SendMessage(aRichEdit.Handle, EM_SETEventMask, 0, EventMask);
end;
end.
Delphi RxRichEdit高级操作的更多相关文章
- delphi的流操作的语法
Delphi在这两方面都做的相当出色.在Delphi的早期版本Turbo Pascal 中就曾有流(Stream).群(Collection)和资源(Resource)等专门用于对象式数据管理的类.在 ...
- [Session] SessionHelper2---C#关于Session高级操作帮助类 (转载)
点击下载 SessionHelper2.rar 这个类是关于Session的一些高级操作1.添加时限制时间2.读取对象3.读取数据等等看下面代码吧 /// <summary> /// 联系 ...
- cassandra高级操作之索引、排序以及分页
本次就给大家讲讲cassandra的高级操作:索引.排序和分页:处于性能的考虑,cassandra对这些支持都比较简单,所以我们不能希望cassandra完全适用于我们的逻辑,而是应该将我们的逻辑设计 ...
- MySQL学习笔记_9_MySQL高级操作(上)
MySQL高级操作(上) 一.MySQL表复制 create table t2 like t1; #复制表结构,t2可以学习到t1所有的表结构 insert into t2 ...
- MySQL学习笔记_10_MySQL高级操作(下)
MySQL高级操作(下) 五.MySQL预处理语句 1.设置预处理stmt,传递一个数据作为where的判断条件 prepare stmt from "select * from table ...
- python列表(list)的使用技巧及高级操作
python列表(list)的使用技巧及高级操作置顶 2018年03月25日 13:39:41 顽劣的石头 阅读数:5478 标签: python extend bisect list enumera ...
- C语言指针的高级操作
C语言指针的高级操作 指针 指针 在上篇博客中我介绍了C语言指针的最基本操作,那么我在这篇博客中会介绍一下C语言指针的一些骚操作. 指向指针的指针 这名字乍一听有点拗口,再次一听就更加拗口了.先看定 ...
- django之创建第8-3个项目-数据库数据提取之高级操作
1.配置test2.html <!DOCTYPE html> <html lang="en"> <head> <meta charset= ...
- SpringMVC整合Mongodb开发,高级操作
开发环境: 操作系统:windows xpMongodb:2.0.6依 赖 包:Spring3.2.2 + spring-data-mongodb-1.3.0 + Spring-data-1.5 + ...
随机推荐
- 1.BOM学习
1.bom.html <html> <head> <title>bom演示</title> <script type="text/jav ...
- 复习一下,? extends T 和 ? super T
前话 最近学一些杂七杂八的东西,都把基础给忘了. 比如Java泛型中的 ? extends T和 ? super T 吧. 刚看开源项目的时候遇到它,表情如下: 源码分析 直接用源码来讲解吧 pack ...
- JavaWeb笔记——利用过滤器实现页面静态化
1.说明 页面静态化是把动态页面生成的html保存到服务器的文件上,然后再有相同请求时,不再去执行动态页面,而是直接给用户响应上次已经生成的静态页面. * 核心思路为拦截请求,实现请求转发指向静态页面 ...
- IDEA中利用JUnit进行单元测试
打开IntelliJ IDEA工具,Alt+Ctrl+S,打开设置窗口,点击进入Plugins. 从插件资源库中搜索JunitGenerator V2.0版本
- MyBatis学习总结_07_Mybatis缓存
一.MyBatis缓存介绍 正如大多数持久层框架一样,MyBatis 同样提供了一级缓存和二级缓存的支持 一级缓存: 基于PerpetualCache 的 HashMap本地缓存,其存储作用域为 Se ...
- SQL Server ->> 关于究竟ALTER INDEX ... REBUILD会不会导致改变索引选项和Filegroup的验证
其实之前做过类型的验证,不过影响不是特别深,只是记得不会改变DATA COMPRESSION,那今天再次遇到这个问题就再拿出来验证一下.随便写个脚本验证下.ALTER INDEX ... REBUIL ...
- python 细枝末节
1. print 自动换行 看区别 >>> for i in range(4): ... print i ... 0 1 2 3 >>> for i in ran ...
- Myeclipse 2014 javascript 添加 jquery 代码提示
近日在写js,在myeclipse中没有jquery代码的提示着实不方便,在网上使用度娘搜索添加提示方式,试了多种,现经测试以下方式可取. 1.打开help菜单下的install from site. ...
- 三方贸易-drop ship
一.三方贸易的简单理解 三方贸易:即当客户向我方下达采购订单要求订购货物,我方再向供应商下达相同采购订单,并要求供应商直接送货至客户处的交易形式,待交易完成后,由供应商向我方开具应收票据,我方向客户开 ...
- [Lintcode two-sum]两数之和(python,双指针)
题目链接:http://www.lintcode.com/zh-cn/problem/two-sum/ 给一个整数数组,找到两个数使得他们的和等于一个给定的数target. 备份一份,然后排序.搞两个 ...