不要用RichEdit!

解决方案 »

  1.   

    有没有好的字符串处理方法?不要用String!
      

  2.   

    uses RpMemo;function  RTFToText(sRTF: String): String;
    var
      AMemo : TMemoBuf;
    begin
      Result := '';
      AMemo := TMemoBuf.Create;
      try
        AMemo.RTFText := sRTF;
        Result := AMemo.Text;
      finally
        AMemo.Free;
      end;
    end;function  RTFFileToText(sRTFFile: String): String;
    var
      AMemo : TMemoBuf;
    begin
      Result := '';
      AMemo := TMemoBuf.Create;
      try
        AMemo.RTFLoadFromFile(sRTFFile);
        Result := AMemo.Text;
      finally
        AMemo.Free;
      end;
    end;procedure TForm1.Button1Click(Sender: TObject);
    begin
      ShowMessage (RTFFileToText('d:\1.rtf'));  ShowMessage (
        RTFToText(
          '{\rtf1\ansi\ansicpg936\deff0\deflang1033\deflangfe2052{\fonttbl{\f0\fmodern\fprq6\fcharset134 \''cb\''ce\''cc\''e5;}}' +
          '{\colortbl ;\red255\green0\blue0;}' +
          '\viewkind4\uc1\pard\cf1\lang2052\f0\fs20 Hello\par' +
          '}'
        )
      );
    end;
      

  3.   

    to jadeluo(秀峰)
    其实我现在就是用的TMemoBuf,但在用的时候发现对中文支持有问题。不知你遇到过这样的问题没。所以现在想换其它的控件!
      

  4.   

    不是我不想用RichEdit,RichEdit必须有容器装载。不知道上面几位为什么挖苦别人!
      

  5.   

    To flybird_lx(flybird)
    我没有仔细测试过TMemoBuf,不知是什么样的情况下,会对中文支持出现问题?
      

  6.   

    to jadeluo(秀峰)
    我也是无意中发现的,在文本中有中文的“”(双引号)时,会出现乱码。我的程序是这样的,用户在RichEdit内输入了格式化的文本,我将其rtf格式的内容保存在字符串内。然后我想在一个地方以非格式化的形式显示其内容。因此就需要将rtf格式转化成txt。但是由于Richedit必须要显示的容器装载,无法满足我的要求,因此我使用了TMemoBuf做转化。但在使用了一段时间后无意间发现了上面说的问题。很郁闷啊。后来下载了Rave5的源代码想直接修改TMemoBuf,一看发现写得很复杂,实在没时间做这个工作了,就想干脆换控件了。所以就想问问除了TMemoBuf还有没有其它处理rtf格式的控件或类。
      

  7.   

    To flybird_lx(flybird)
    测试了一下,正如你所说的,在处理中文的引号时有问题,对应的RTF代码应该是\ldblquote和\rdblquote,还不知道该如何解决。
      

  8.   

    还是用了RichEdit。它的ParentWindow设置为系统桌面,这样能解决容器的问题。uses ComCtrls;function  RTFToText(sRTF: String): String;
    var
      AMemo : TRichEdit;
    begin
      Result := '';
      AMemo := TRichEdit.Create(nil);
      try
        AMemo.ParentWindow := GetDesktopWindow();
        AMemo.SelText := sRTF;
        Result := AMemo.Text;
      finally
        AMemo.Free;
      end;
    end;function  RTFFileToText(sRTFFile: String): String;
    var
      AMemo : TRichEdit;
    begin
      Result := '';
      AMemo := TRichEdit.Create(nil);
      try
        AMemo.ParentWindow := GetDesktopWindow();
        AMemo.Lines.LoadFromFile(sRTFFile);
        Result := AMemo.Text;
      finally
        AMemo.Free;
      end;
    end;procedure TForm1.Button1Click(Sender: TObject);
    begin
      ShowMessage (RTFFileToText('d:\1.rtf'));  ShowMessage (
        RTFToText(
          '{\rtf1\ansi\ansicpg936\deff0\deflang1033\deflangfe2052{\fonttbl{\f0\fmodern\fprq6\fcharset134 \''cb\''ce\''cc\''e5;}}' +
          '\viewkind4\uc1\pard\lang2052\f0\fs20\''ba\''ba\''d7\''d6\par' +
          '\ldblquote\''d6\''d0\''ce\''c4\rdblquote\par' +
          '}'
        )
      );
    end;
      

  9.   

    to jadeluo(秀峰)
    非常感谢你的帮助,准备用你说的方法了!