RichView13.12 Stream read error 原因分析

来源:互联网 发布:msn聊天软件 编辑:程序博客网 时间:2024/06/04 23:36

RichView13.12 Stream read error 

有选中文本时,调用RichViewEdit1.GetSelText;方法会报错,

发现这个版本最终调用

function TCustomRVFormattedData.GetSelTextR(Unicode: Boolean): TRVRawByteString;
var Stream: TRVMemoryStream;
begin
  {$IFNDEF RVDONOTUSEINPLACE}
  if (GetChosenRVData<>nil) then begin
    Result := TCustomRVFormattedData(GetChosenRVData).GetSelTextR(Unicode);
    exit;
  end;
  {$ENDIF}
  if not SelectionExists(False, True) then begin
    Result := '';
    exit;
  end;
  Stream := TRVMemoryStream.Create;
  try
    if SaveTextToStream('', Stream, 80, True, True, Unicode, False, CP_ACP, True) then begin//  RVMemoryStream.Write
      SetLength(Result, Stream.Size);
      Stream.Position := 0;
      Stream.ReadBuffer(PRVAnsiChar(Result)^, Stream.Size);
      end
    else
      Result := '';
  finally
    Stream.Free;
  end;
end;

write函数由于子类TRVMemoryStream有重载,所以调用了子类的write方法,对子类的Fsize赋值了,就不调用父类的write方法了,Fsize是TRVMemoryStream的私有成员,所以父类的Fsize并未赋值。导致后面调用父类TStream.ReadBuffe函数时,Fsize为0,子类没有相应的readbuffer函数,只能调用父类的read函数,所以你类函数后面报错了。最新版本XE4增加了重载ReadBuffer函数,这样最终Read调用了子类TRVMemoryStream的Read方法,完成了读功能,而不调用父类的read方法,所以就不出错了。

原创粉丝点击