anchor.diff:    end;
   end;
   
  -function TfpgMemo.SelectionText: string;
  -begin
  -  {
  -  if FSelOffset <> 0 then
  -  begin
  -    if FSelOffset < 0 then
  -    begin
  -      Result := Copy(FText,1+FSelStart + FSelOffset,-FSelOffset);
  -    end
  -    else
  -    begin
  -      result := Copy(FText,1+FSelStart,FSelOffset);
  -    end;
  +function TfpgMemo.SelectionText: TfpgString;
  +var
  +  n: integer;
  +  selsl: integer;
  +  selsp: integer;
  +  selel: integer;
  +  selep: integer;
  +  ls: string;
  +  len: integer;
  +  st: integer;
  +  s: TfpgString;
  +begin
  +  if (FSelStartLine shl 16) + FSelStartPos <= (FSelEndLine shl 16) + FSelEndPos then
  +  begin
  +    selsl := FSelStartLine;
  +    selsp := FSelStartPos;
  +    selel := FSelEndLine;
  +    selep := FSelEndPos;
     end
     else
  -}
  -    Result := '';
  +  begin
  +    selel := FSelStartLine;
  +    selep := FSelStartPos;
  +    selsl := FSelEndLine;
  +    selsp := FSelEndPos;
  +  end;
  +
  +  s := '';
  +  for n := selsl to selel do
  +  begin
  +    if n > selsl then
  +      s := s + LineEnding;
  +
  +    ls := GetLineText(n);
  +
  +    if selsl < n then
  +      st := 0
  +    else
  +      st := selsp;
  +
  +    if selel > n then
  +      len := UTF8Length(ls)
  +    else
  +      len := selep - st;
  +
  +    s := s + UTF8Copy(ls, st + 1, len);
  +  end;
  +
  +  Result := s;
   end;
   
   procedure TfpgMemo.CopyToClipboard;
  
positive.code: end;
  
  procedure TfpgMemo.DoCopy;
  var
    n: integer;
    selsl: integer;
    selsp: integer;
    selel: integer;
    selep: integer;
    ls: string;
    len: integer;
    st: integer;
    s: string;
  begin
    if FSelEndLine < 0 then
      Exit;
  
    if (FSelStartLine shl 16) + FSelStartPos <= (FSelEndLine shl 16) + FSelEndPos then
    begin
      selsl := FSelStartLine;
      selsp := FSelStartPos;
      selel := FSelEndLine;
      selep := FSelEndPos;
    end
    else
    begin
      selel := FSelStartLine;
      selep := FSelStartPos;
      selsl := FSelEndLine;
      selsp := FSelEndPos;
    end;
  
    s := '';
  
    for n := selsl to selel do
    begin
      if n > selsl then
        s := s + #13#10;
  
      ls := GetLineText(n);
  
      if selsl < n then
        st := 0
      else
        st := selsp;
  
      if selel > n then
        len := UTF8Length(ls)
      else
        len := selep - st;
  
      s := s + UTF8Copy(ls, st + 1, len);
    end;
  
    fpgClipboard.Text := s;
  end;
  
  procedure TfpgMemo.DoPaste(const AText: TfpgString);
  
negative.code:     constructor Create(AOwner: TComponent); override;
      destructor  Destroy; override;
      procedure   UpdateScrollBars;
      function    SelectionText: TfpgString;
      procedure   CopyToClipboard;
      procedure   CutToClipboard;
      procedure   PasteFromClipboard;
  