📄 clipboardutils.pas
字号:
unit ClipBoardUtils;
interface
uses
Clipbrd, Classes, Contnrs;
type
TFormatData = record
f: Cardinal;
DataSize: Integer;
Data: PChar;
end;
TSuperClipData = class(TClipboard)
public
procedure GetDataWithFormat(AFormatData: TFormatData);
end;
function SuperClipData: TSuperClipData;
type
TClipData = class
private
FormatList: array of TFormatData;
function GetFormat(index: Integer): TFormatData;
procedure LoadFromClip;
function GetFormatCount: Integer;
procedure SetFormat(index: Integer; const Value: TFormatData);
public
procedure WriteToStream(Stream: TStream);
constructor Create(Tag: Integer);
destructor Destroy; override;
property FormatCount: Integer read GetFormatCount;
property Format[index: Integer]: TFormatData read GetFormat write SetFormat;
end;
implementation
uses
Windows;
{ TSuperClipData }
procedure TSuperClipData.GetDataWithFormat(AFormatData: TFormatData);
var
G: HGLOBAL;
Data: PChar;
begin
Open;
try
if HasFormat(AFormatData.f) then
begin
G := GetClipboardData(AFormatData.f);
if g <> 0 then
begin
Data := GlobalLock(G);
AFormatData.DataSize := GlobalSize(G);
if Data <> nil then
begin
GetMem(AFormatData.Data, AFormatData.DataSize);
Move(Data^, AFormatData.Data^, AFormatData.DataSize);
end;
end;
end;
finally
Close;
end;
end;
var
FClipboard: TSuperClipData;
function SuperClipData: TSuperClipData;
begin
if FClipboard = nil then
FClipboard := TSuperClipData.Create;
Result := FClipboard;
end;
{ TClipData }
constructor TClipData.Create(Tag: Integer);
begin
LoadFromClip;
end;
destructor TClipData.Destroy;
begin
inherited;
end;
function TClipData.GetFormat(index: Integer): TFormatData;
begin
if (index >= 0) and (index < FormatCount) then
Result := FormatList[index];
end;
function TClipData.GetFormatCount: Integer;
begin
Result := Length(FormatList);
end;
procedure TClipData.LoadFromClip;
var
I: Integer;
begin
SetLength(FormatList, SuperClipData.FormatCount);
for I := 0 to SuperClipData.FormatCount - 1 do
begin
FormatList[I].f := SuperClipData.Formats[I];
SuperClipData.GetDataWithFormat(FormatList[I]);
end;
end;
procedure TClipData.SetFormat(index: Integer; const Value: TFormatData);
begin
end;
procedure TClipData.WriteToStream(Stream: TStream);
begin
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -