全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:2121
推到 Plurk!
推到 Facebook!

請教怎樣將RxRichEdit1 的內容合併到 RxRichEdit2?

尚未結案
GoldBoy
一般會員


發表:7
回覆:13
積分:4
註冊:2004-06-08

發送簡訊給我
#1 引用回覆 回覆 發表時間:2004-07-01 19:40:28 IP:219.133.xxx.xxx 未訂閱
http://delphi.ktop.com.tw/topic.php?TOPIC_ID=52375 我還是無法將 RxRichEdit1 的內容合併到 RxRichEdit2 ,用剪切板 有時候會發生衝突 用 TMemoryStream 合併也行步通 ,可能是我寫錯了,出來的結果不成功! 請版主幫幫忙,我真的想不到其他的變法了! 麻煩你們了,謝謝~
hagar
版主


發表:143
回覆:4056
積分:4445
註冊:2002-04-14

發送簡訊給我
#2 引用回覆 回覆 發表時間:2004-07-02 08:02:34 IP:202.39.xxx.xxx 未訂閱
測試方法: 在 RxRichEdit1 與 RxRichEdit2 上各輸入些文字, 並加以變化 然後在 RxRichEdit1 上選取要插入至 RxRichEdit2 上的字 按下 Button1 將游標點在 RxRichEdit2 上要插入 RxRichEdit1 內容的位置 然後按下 Button2 即可看到 RxRichEdit1 上中被選取的內容已插入 RxRichEdit2 中
unit Unit1;    interface    uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, RichEdit, RxRichEd;    type
  TForm1 = class(TForm)
    RxRichEdit1: TRxRichEdit;
    RxRichEdit2: TRxRichEdit;
    Button1: TButton;
    Memo1: TMemo;
    Button2: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;    Type
  // These declarations are wrong in richedit.pas, the stdcall is missing.
  TEditStreamCallBack = function (dwCookie: Longint; pbBuff: PByte;
    cb: Longint; var pcb: Longint): Longint; stdcall;      TEditStream = record
    dwCookie: Longint;
    dwError: Longint;
    pfnCallback: TEditStreamCallBack;
  end;    var
  Form1: TForm1;    implementation    {$R *.DFM}    Function EditStreamInCallback(dwCookie: Longint; pbBuff: PByte;
    cb: Longint; var pcb: Longint): Longint; stdcall;
var
  theStream: TStream;
  dataAvail: LongInt;
begin
  theStream := TStream(dwCookie);      with theStream do
  begin
    dataAvail := Size - Position;
    if dataAvail <= cb then
    begin
      pcb := Read(pbBuff^, dataAvail);
      Result := 0;
    end
    else
    begin
      pcb := Read(pbBuff^, cb);
      Result := pcb;
    end;
  end;
end;    Function EditStreamOutCallback(dwCookie: Longint; pbBuff: PByte;
    cb: Longint; var pcb: Longint): Longint; stdcall;
var
  theStream: TStream;
begin
  theStream := TStream(dwCookie);      with theStream do
  begin
    If cb > 0 Then
    Begin
      pcb := Write(pbBuff^, cb);
      Result := pcb;
    End
    Else
      Result := 0;
  end;
end;    Procedure GetRTFSelection(ARxRichEdit: TRxRichEdit; intoStream: TStream);
Var
  editstream: TEditStream;
Begin
  With editstream Do
  Begin
    dwCookie := Longint(intoStream);
    dwError := 0;
    pfnCallback := EditStreamOutCallBack;
  end;
  ARxRichedit.Perform(EM_STREAMOUT, SF_RTF or SFF_SELECTION, longint(@editstream));
End;    Procedure PutRTFSelection(ARxRichEdit: TRxRichEdit; sourceStream: TStream);
Var
  editstream: TEditStream;
Begin
  With editstream Do
  Begin
    dwCookie := Longint(sourceStream);
    dwError := 0;
    pfnCallback := EditStreamInCallBack;
  end;
  ARxRichedit.Perform(EM_STREAMIN, SF_RTF or SFF_SELECTION, longint(@editstream));
End;    procedure TForm1.Button1Click(Sender: TObject);
Var
  aMemStream: TMemoryStream;
begin
  aMemStream := TMemoryStream.Create;
  try
    GetRTFSelection(RxRichEdit1, aMemStream);
    aMemStream.Position := 0;
    memo1.Lines.LoadFromStream(aMemStream);
  finally
    aMemStream.Free;
  end;
end;    procedure TForm1.Button2Click(Sender: TObject);
Var
  aMemStream: TMemoryStream;
begin
  aMemStream := TMemoryStream.Create;
  try
    memo1.Lines.SaveToStream(aMemStream);
    aMemStream.Position := 0;
    PutRTFSelection(RxRichEdit2, aMemStream);
  finally
    aMemStream.Free;
  end;
end;    end.
參考 Peter Below 大大的連結: http://groups.google.com.tw/groups?hl=zh-TW&lr=&ie=UTF-8&selm=VA.00000a91.0005d52b%40noname -- Everything I say is a lie.
GoldBoy
一般會員


發表:7
回覆:13
積分:4
註冊:2004-06-08

發送簡訊給我
#3 引用回覆 回覆 發表時間:2004-07-02 10:06:56 IP:61.145.xxx.xxx 未訂閱
謝謝 hagar 大大,搞定了!
GoldBoy
一般會員


發表:7
回覆:13
積分:4
註冊:2004-06-08

發送簡訊給我
#4 引用回覆 回覆 發表時間:2004-07-02 11:10:31 IP:219.133.xxx.xxx 未訂閱
糟糕了,上面的方法,只能處理文字,如果包括圖片就不行了~~
GoldBoy
一般會員


發表:7
回覆:13
積分:4
註冊:2004-06-08

發送簡訊給我
#5 引用回覆 回覆 發表時間:2004-07-02 16:40:13 IP:218.18.xxx.xxx 未訂閱
這樣就可以解決了~  > > > >
mayday741130
一般會員


發表:11
回覆:8
積分:3
註冊:2006-07-22

發送簡訊給我
#6 引用回覆 回覆 發表時間:2007-02-11 11:25:13 IP:210.70.xxx.xxx 訂閱
想問有這個的RxRichEd.pas檔嗎........?
因為沒辦法執行........
------
小LO
系統時間:2024-04-26 20:17:08
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!