Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Win32/Win64 API (native code) (https://www.delphipraxis.net/17-win32-win64-api-native-code/)
-   -   Delphi HTML-Content aus dem Clipboard holen? (https://www.delphipraxis.net/173913-html-content-aus-dem-clipboard-holen.html)

PeterPanino 23. Mär 2013 23:26

HTML-Content aus dem Clipboard holen?
 
Hallo! Ich möchte in Delphi XE2 mit folgender Funktion den HTML-Content aus dem Clipboard holen:

Delphi-Quellcode:
uses ... Vcl.Clipbrd, Winapi.Windows, Winapi.ActiveX;

CF_HTML: TClipFormat; // identifier for HTML clipboard format
CF_HTML := RegisterClipboardFormat('HTML Format');

function MyClipboardAsHTML: string;
var
  Data: THandle;
  Ptr: PChar;
begin
  Result := '';
  with Clipboard do
  begin
    Open;
    try
      Data := GetAsHandle(CF_HTML);
      if Data <> 0 then
      begin
        Ptr := PChar(GlobalLock(Data));
        if Ptr <> nil then
          try
            Result := UTF8Decode((Ptr));
          finally
            GlobalUnlock(Data);
          end;
      end;
    finally
      Close;
    end;
  end;
end;
Leider kriege ich aber nur Zeichensalat. (Natürlich ist HTML-Content im Clipboard).

Ich habe alles mögliche probiert, komme aber nicht auf den Fehler.

sx2008 23. Mär 2013 23:45

AW: HTML-Content aus dem Clipboard holen?
 
PChar?
UTF-8 Strings werden doch sicher als Multibyte-Daten im Clipboard abgelegt.
Also müsste wohl PAnsiString verwendet werden weil ja PChar unter Delphi XE 2 Bytes pro Zeichen bedeutet.

PeterPanino 24. Mär 2013 00:11

AW: HTML-Content aus dem Clipboard holen?
 
Ich verstehe nicht wie du das meinst.

sx2008 24. Mär 2013 00:19

AW: HTML-Content aus dem Clipboard holen?
 
Delphi-Quellcode:
function MyClipboardAsHTML: string;
var
  Data: THandle;
  Ptr: PAnsiChar; // *** statt PChar
begin
  Result := '';
  with Clipboard do
  begin
    Open;
    try
      Data := GetAsHandle(CF_HTML);
      if Data <> 0 then
      begin
        Ptr := PAnsiChar(GlobalLock(Data)) // *** statt PChar

PeterPanino 24. Mär 2013 00:28

AW: HTML-Content aus dem Clipboard holen?
 
Fantastisch! Es funktioniert! Vielen Dank!!!!


Alle Zeitangaben in WEZ +1. Es ist jetzt 09:58 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz