Delphi  RxRichEdit高级操作-LMLPHPunit InsertRichEditUnit;
Delphi  RxRichEdit高级操作-LMLPHP
Delphi  RxRichEdit高级操作-LMLPHPinterface
Delphi  RxRichEdit高级操作-LMLPHP
Delphi  RxRichEdit高级操作-LMLPHPuses
Delphi  RxRichEdit高级操作-LMLPHP  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Delphi  RxRichEdit高级操作-LMLPHP  StdCtrls, RichEdit, UHISRichEd;
Delphi  RxRichEdit高级操作-LMLPHP
Delphi  RxRichEdit高级操作-LMLPHPtype
Delphi  RxRichEdit高级操作-LMLPHP  TEditStreamCallBack = function(dwCookie: Longint; pbBuff: PByte; cb: Longint;
Delphi  RxRichEdit高级操作-LMLPHP    var pcb: Longint): DWORD; stdcall;
Delphi  RxRichEdit高级操作-LMLPHP
Delphi  RxRichEdit高级操作-LMLPHP  TEditStream = record
Delphi  RxRichEdit高级操作-LMLPHP    dwCookie: Longint;
Delphi  RxRichEdit高级操作-LMLPHP    dwError: Longint;
Delphi  RxRichEdit高级操作-LMLPHP    pfnCallback: TEditStreamCallBack;
Delphi  RxRichEdit高级操作-LMLPHP  end;
Delphi  RxRichEdit高级操作-LMLPHP
Delphi  RxRichEdit高级操作-LMLPHPprocedure GetRTFSelection(aRichEdit: TUHISRichEdit; IntoStream: TStream);
Delphi  RxRichEdit高级操作-LMLPHPprocedure PutRTFSelection(aRichEdit: TUHISRichEdit; SourceStream: TStream);
Delphi  RxRichEdit高级操作-LMLPHPprocedure InsertRTF(aRichEdit: TUHISRichEdit; S: string);
Delphi  RxRichEdit高级操作-LMLPHPprocedure CopyRTF(aSource, aDest: TUHISRichEdit);
Delphi  RxRichEdit高级操作-LMLPHPprocedure CopyAllRTF(aSource, aDest: TUHISRichEdit);
Delphi  RxRichEdit高级操作-LMLPHPprocedure AppendRTF(aRichEdit: TUHISRichEdit; S: string);
Delphi  RxRichEdit高级操作-LMLPHP
Delphi  RxRichEdit高级操作-LMLPHPimplementation
Delphi  RxRichEdit高级操作-LMLPHP
Delphi  RxRichEdit高级操作-LMLPHPfunction EditStreamInCallback(dwCookie: Longint; pbBuff: PByte; cb: Longint;
Delphi  RxRichEdit高级操作-LMLPHP  var pcb: Longint): DWORD; stdcall;
Delphi  RxRichEdit高级操作-LMLPHPvar
Delphi  RxRichEdit高级操作-LMLPHP  TheStream: TStream;
Delphi  RxRichEdit高级操作-LMLPHP  DataAvail: LongInt;
Delphi  RxRichEdit高级操作-LMLPHPbegin
Delphi  RxRichEdit高级操作-LMLPHP  TheStream := TStream(dwCookie);
Delphi  RxRichEdit高级操作-LMLPHP  with TheStream do
Delphi  RxRichEdit高级操作-LMLPHP  begin
Delphi  RxRichEdit高级操作-LMLPHP    DataAvail := Size - Position;
Delphi  RxRichEdit高级操作-LMLPHP    Result := 0;
Delphi  RxRichEdit高级操作-LMLPHP    if DataAvail <= cb then
Delphi  RxRichEdit高级操作-LMLPHP    begin
Delphi  RxRichEdit高级操作-LMLPHP      pcb := Read(pbBuff^, DataAvail);
Delphi  RxRichEdit高级操作-LMLPHP      if pcb <> DataAvail then
Delphi  RxRichEdit高级操作-LMLPHP        result := DWord(E_FAIL);
Delphi  RxRichEdit高级操作-LMLPHP    end
Delphi  RxRichEdit高级操作-LMLPHP    else
Delphi  RxRichEdit高级操作-LMLPHP    begin
Delphi  RxRichEdit高级操作-LMLPHP      pcb := Read(pbBuff^, cb);
Delphi  RxRichEdit高级操作-LMLPHP      if pcb <> cb then
Delphi  RxRichEdit高级操作-LMLPHP        result := DWord(E_FAIL);
Delphi  RxRichEdit高级操作-LMLPHP    end;
Delphi  RxRichEdit高级操作-LMLPHP  end;
Delphi  RxRichEdit高级操作-LMLPHP  TheStream := TStream(dwCookie);
Delphi  RxRichEdit高级操作-LMLPHPend;
Delphi  RxRichEdit高级操作-LMLPHP
Delphi  RxRichEdit高级操作-LMLPHPfunction EditStreamOutCallback(dwCookie: Longint; pbBuff: PByte; cb: Longint;
Delphi  RxRichEdit高级操作-LMLPHP  var pcb: Longint): DWORD; stdcall;
Delphi  RxRichEdit高级操作-LMLPHPvar
Delphi  RxRichEdit高级操作-LMLPHP  TheStream: TStream;
Delphi  RxRichEdit高级操作-LMLPHPbegin
Delphi  RxRichEdit高级操作-LMLPHP  TheStream := TStream(dwCookie);
Delphi  RxRichEdit高级操作-LMLPHP  with TheStream do
Delphi  RxRichEdit高级操作-LMLPHP  begin
Delphi  RxRichEdit高级操作-LMLPHP    if cb > 0 then
Delphi  RxRichEdit高级操作-LMLPHP      pcb := Write(pbBuff^, cb);
Delphi  RxRichEdit高级操作-LMLPHP    Result := 0;
Delphi  RxRichEdit高级操作-LMLPHP  end;
Delphi  RxRichEdit高级操作-LMLPHPend;
Delphi  RxRichEdit高级操作-LMLPHP
Delphi  RxRichEdit高级操作-LMLPHPprocedure GetRTFSelection(aRichEdit: TUHISRichEdit; IntoStream: TStream);
Delphi  RxRichEdit高级操作-LMLPHPvar
Delphi  RxRichEdit高级操作-LMLPHP  EditStream: TEditStream;
Delphi  RxRichEdit高级操作-LMLPHPbegin
Delphi  RxRichEdit高级操作-LMLPHP  with EditStream do
Delphi  RxRichEdit高级操作-LMLPHP  begin
Delphi  RxRichEdit高级操作-LMLPHP    dwCookie := Longint(IntoStream);
Delphi  RxRichEdit高级操作-LMLPHP    dwError := 0;
Delphi  RxRichEdit高级操作-LMLPHP    pfnCallback := EditStreamOutCallBack;
Delphi  RxRichEdit高级操作-LMLPHP  end;
Delphi  RxRichEdit高级操作-LMLPHP  aRichEdit.Perform(EM_STREAMOUT, SF_RTF or SFF_SELECTION, longint(@EditStream));
Delphi  RxRichEdit高级操作-LMLPHPend;
Delphi  RxRichEdit高级操作-LMLPHP
Delphi  RxRichEdit高级操作-LMLPHPprocedure PutRTFSelection(aRichEdit: TUHISRichEdit; SourceStream: TStream);
Delphi  RxRichEdit高级操作-LMLPHPvar
Delphi  RxRichEdit高级操作-LMLPHP  EditStream: TEditStream;
Delphi  RxRichEdit高级操作-LMLPHPbegin
Delphi  RxRichEdit高级操作-LMLPHP  with EditStream do
Delphi  RxRichEdit高级操作-LMLPHP  begin
Delphi  RxRichEdit高级操作-LMLPHP    dwCookie := Longint(SourceStream);
Delphi  RxRichEdit高级操作-LMLPHP    dwError := 0;
Delphi  RxRichEdit高级操作-LMLPHP    pfnCallback := EditStreamInCallBack;
Delphi  RxRichEdit高级操作-LMLPHP  end;
Delphi  RxRichEdit高级操作-LMLPHP  aRichEdit.Perform(EM_STREAMIN, SF_RTF or SFF_SELECTION, longint(@EditStream));
Delphi  RxRichEdit高级操作-LMLPHPend;
Delphi  RxRichEdit高级操作-LMLPHP
Delphi  RxRichEdit高级操作-LMLPHPprocedure InsertRTF(aRichEdit: TUHISRichEdit; S: string);
Delphi  RxRichEdit高级操作-LMLPHPvar
Delphi  RxRichEdit高级操作-LMLPHP  aMemStream: TMemoryStream;
Delphi  RxRichEdit高级操作-LMLPHPbegin
Delphi  RxRichEdit高级操作-LMLPHP  if Length(S) > 0 then
Delphi  RxRichEdit高级操作-LMLPHP  begin
Delphi  RxRichEdit高级操作-LMLPHP    aMemStream := TMemoryStream.Create;
Delphi  RxRichEdit高级操作-LMLPHP    try
Delphi  RxRichEdit高级操作-LMLPHP      aMemStream.Write(S[1], length(S));
Delphi  RxRichEdit高级操作-LMLPHP      aMemStream.Position := 0;
Delphi  RxRichEdit高级操作-LMLPHP      PutRTFSelection(aRichEdit, aMemStream);
Delphi  RxRichEdit高级操作-LMLPHP    finally
Delphi  RxRichEdit高级操作-LMLPHP      aMemStream.Free;
Delphi  RxRichEdit高级操作-LMLPHP    end;
Delphi  RxRichEdit高级操作-LMLPHP  end;
Delphi  RxRichEdit高级操作-LMLPHPend;
Delphi  RxRichEdit高级操作-LMLPHP
Delphi  RxRichEdit高级操作-LMLPHPprocedure CopyRTF(aSource, aDest: TUHISRichEdit);
Delphi  RxRichEdit高级操作-LMLPHPvar
Delphi  RxRichEdit高级操作-LMLPHP  aMemStream: TMemoryStream;
Delphi  RxRichEdit高级操作-LMLPHPbegin
Delphi  RxRichEdit高级操作-LMLPHP  aMemStream := TMemoryStream.Create;
Delphi  RxRichEdit高级操作-LMLPHP  try
Delphi  RxRichEdit高级操作-LMLPHP    GetRTFSelection(aSource, aMemStream);
Delphi  RxRichEdit高级操作-LMLPHP    aMemStream.Position := 0;
Delphi  RxRichEdit高级操作-LMLPHP    PutRTFSelection(aDest, aMemStream);
Delphi  RxRichEdit高级操作-LMLPHP  finally
Delphi  RxRichEdit高级操作-LMLPHP    aMemStream.Free;
Delphi  RxRichEdit高级操作-LMLPHP  end;
Delphi  RxRichEdit高级操作-LMLPHPend;
Delphi  RxRichEdit高级操作-LMLPHP
Delphi  RxRichEdit高级操作-LMLPHPprocedure CopyAllRTF(aSource, aDest: TUHISRichEdit);
Delphi  RxRichEdit高级操作-LMLPHPvar
Delphi  RxRichEdit高级操作-LMLPHP  aMemStream: TMemoryStream;
Delphi  RxRichEdit高级操作-LMLPHPbegin
Delphi  RxRichEdit高级操作-LMLPHP  aMemStream := TMemoryStream.Create;
Delphi  RxRichEdit高级操作-LMLPHP  try
Delphi  RxRichEdit高级操作-LMLPHP    aSource.SelectAll;
Delphi  RxRichEdit高级操作-LMLPHP    GetRTFSelection(aSource, aMemStream);
Delphi  RxRichEdit高级操作-LMLPHP    aMemStream.Position := 0;
Delphi  RxRichEdit高级操作-LMLPHP    aDest.SelStart := Length(aDest.Lines.Text);
Delphi  RxRichEdit高级操作-LMLPHP    PutRTFSelection(aDest, aMemStream);
Delphi  RxRichEdit高级操作-LMLPHP  finally
Delphi  RxRichEdit高级操作-LMLPHP    aMemStream.Free;
Delphi  RxRichEdit高级操作-LMLPHP  end;
Delphi  RxRichEdit高级操作-LMLPHPend;
Delphi  RxRichEdit高级操作-LMLPHP
Delphi  RxRichEdit高级操作-LMLPHPprocedure AppendRTF(aRichEdit: TUHISRichEdit; S: string);
Delphi  RxRichEdit高级操作-LMLPHPvar
Delphi  RxRichEdit高级操作-LMLPHP  Start, Length, EventMask: Integer;
Delphi  RxRichEdit高级操作-LMLPHPbegin
Delphi  RxRichEdit高级操作-LMLPHP  EventMask := SendMessage(aRichEdit.Handle, EM_SETEventMask, 0, 0);
Delphi  RxRichEdit高级操作-LMLPHP  SendMessage(aRichEdit.Handle, WM_SETREDRAW, 0, 0);
Delphi  RxRichEdit高级操作-LMLPHP  Start := aRichEdit.SelStart;
Delphi  RxRichEdit高级操作-LMLPHP  Length := aRichEdit.SelLength;
Delphi  RxRichEdit高级操作-LMLPHP  aRichEdit.SelLength := 0;
Delphi  RxRichEdit高级操作-LMLPHP  aRichEdit.SelStart := System.Length(aRichEdit.Text);
Delphi  RxRichEdit高级操作-LMLPHP  InsertRTF(aRichEdit, s);
Delphi  RxRichEdit高级操作-LMLPHP  aRichEdit.SelStart := Start;
Delphi  RxRichEdit高级操作-LMLPHP  aRichEdit.SelLength := Length;
Delphi  RxRichEdit高级操作-LMLPHP  SendMessage(aRichEdit.Handle, WM_SETREDRAW, 1, 0);
Delphi  RxRichEdit高级操作-LMLPHP  InvalidateRect(aRichEdit.Handle, nil, True);
Delphi  RxRichEdit高级操作-LMLPHP  SendMessage(aRichEdit.Handle, EM_SETEventMask, 0, EventMask);
Delphi  RxRichEdit高级操作-LMLPHPend;
Delphi  RxRichEdit高级操作-LMLPHP
Delphi  RxRichEdit高级操作-LMLPHPend.

05-11 10:49