Einzelnen Beitrag anzeigen

Benutzerbild von haentschman
haentschman
Online

Registriert seit: 24. Okt 2006
Ort: Seifhennersdorf / Sachsen
5.388 Beiträge
 
Delphi 12 Athens
 
#9

AW: Zwischenablage Zugriff verweigert

  Alt 16. Aug 2022, 14:22
...ich habe das mal im TcxCustomTextEdit.PasteFromClipboard integriert
Delphi-Quellcode:
procedure TcxCustomTextEdit.PasteFromClipboard;
var
  ANewSelStart: Integer;
  ANewText, S: string;

  function GetClipboardText: string;
  var
    RetryCount: Integer;
    Success: Boolean;
  begin
    RetryCount := 0;
    Success := False;
    while not Success do
    begin
      try
        Result := Clipboard.AsText;
        Success := True;
      except
        on EClipboardException do
        begin
          Inc(RetryCount);
          if RetryCount < 50 then
          begin
            Sleep(20)
          end
          else
          begin
            raise Exception.Create('Cannot read clipboard after fifty attempts');
            // Exit(''); // Alternativ statt raise
          end;
        end
        else
          raise;
      end;
    end;
  end;

begin
  if Clipboard.HasFormat(CF_TEXT) then
  begin
    if Focused then
    begin
      BeginUserAction;
      try
        S := GetClipboardText;
        if CanChangeSelText(S, ANewText, ANewSelStart) then
          InnerEdit.CallDefWndProc(WM_PASTE, 0, 0);
      finally
        EndUserAction;
      end;
    end
    else
      SelText := GetClipboardText;
  end;
end;
  Mit Zitat antworten Zitat