gpt4 book ai didi

delphi - 如何检查是否已成功从剪贴板获取文件名列表?

转载 作者:行者123 更新时间:2023-12-02 02:52:03 26 4
gpt4 key购买 nike

我刚刚找到了这段代码来从剪贴板获取文件,它工作正常,但我想将其设为 bool 函数,以便我知道它成功了。我需要测试什么来查看剪贴板上是否有文件并且一切正常?

USES Clipbrd, shellapi;

// procedure GetFileNameFromClipboard(oSL : TStringlist);
function GetFileNameFromClipboard(oSL : TStringlist) : Boolean;
var
f: THandle;
buffer: array [0..MAX_PATH] of Char;
i, c: Integer;
begin
Result:=False;
if NOT Clipboard.HasFormat(CF_HDROP) then exit;
Clipboard.Open;
f := Clipboard.GetAsHandle(CF_HDROP);
if f <> 0 then
begin
c := DragQueryFile(f, $FFFFFFFF, nil, 0);
for i:=0 to c-1 do
begin
buffer[0] := #0;
DragQueryFile(f, i, buffer, SizeOf(buffer));
oSL.Add(buffer);
end;
end;
Clipboard.Close;
Result:=???????
end;

最佳答案

尝试这样的事情:

function GetFileNameFromClipboard(oSL : TStrings) : Boolean;
var
f: THandle;
buffer: array [0..MAX_PATH] of Char;
S: string;
i, c: UINT;
begin
Result := False;
Clipboard.Open;
try
f := Clipboard.GetAsHandle(CF_HDROP);
if f = 0 then Exit;
c := DragQueryFile(f, $FFFFFFFF, nil, 0);
if c = 0 then Exit;
for i := 0 to c-1 do
begin
c := DragQueryFile(f, i, buffer, Length(buffer));
if c <> 0 then begin
SetString(s, buffer, c);
oSL.Add(s);
Result := True;
end;
end;
finally
Clipboard.Close;
end;
end;

关于delphi - 如何检查是否已成功从剪贴板获取文件名列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17011609/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com