判断文件夹是否共享的DELPHI代码

时间:2010-01-26 12:53:28  来源:第二电脑网  作者:第二电脑网

  第二电脑网导读:StrRetToString(PIDL: PItemIDList; StrRet: TStrRet; Flag: string = ‘‘): string;varP: PChar;begin  case StrRet.uType of  STRRET_CSTR:  SetString(Result, StrRet.cStr, lStrLen(StrRet.cStr));  STRRET_OFFSET:  begin    P := @PIDL.mkid.abID[...
  正文:

以下代码用于判定文件夹是否共享的Delphi代码:

uses ShlObj, ComObj, ActiveX;

function TForm1.IfFolderShared(FullFolderPath: string): Boolean;

//Convert TStrRet to string
function StrRetToString(PIDL: PItemIDList; StrRet: TStrRet; Flag: string = ‘‘): string;
var
P: PChar;
begin
  case StrRet.uType of
  STRRET_CSTR:
  SetString(Result, StrRet.cStr, lStrLen(StrRet.cStr));
  STRRET_OFFSET:
  begin
    P := @PIDL.mkid.abID[StrRet.uOffset - SizeOf(PIDL.mkid.cb)];
    SetString(Result, P, PIDL.mkid.cb - StrRet.uOffset);
  end;
  STRRET_WSTR:
  if Assigned(StrRet.pOleStr) then
  Result := StrRet.pOleStr
  else
  Result := ‘‘;
end;
{ This is a hack bug fix to get around Windows Shell Controls returning
spurious "?"s in date/time detail fields }

if (Length(Result) > 1) and (Result[1] = ‘?‘) and (Result[2] in [‘0‘..‘9‘]) then
Result := StringReplace(Result, ‘?‘, ‘‘, [rfReplaceAll]);
end;

//Get Desktop‘s IShellFolder interface
function Desktophotoshop/ target=_blank class=infotextkey>pshellFolder: IShellFolder;
begin
  OleCheck(SHGetDesktopFolder(Result));
end;

//delete the first ID from IDList
function NextPIDL(IDList: PItemIDList): PItemIDList;
begin
  Result := IDList;
  Inc(PChar(Result), IDList^.mkid.cb);
end;

//get the length of IDList
function GetPIDLSize(IDList: PItemIDList): Integer;
begin
  Result := 0;
  if Assigned(IDList) then
  begin
    Result := SizeOf(IDList^.mkid.cb);
    while IDList^.mkid.cb <> 0 do
    begin
      Result := Result + IDList^.mkid.cb;
      IDList := NextPIDL(IDList);
    end;
  end;
end;

//get ID count from IDList
function GetItemCount(IDList: PItemIDList): Integer;
begin
  Result := 0;
  while IDList^.mkid.cb <> 0 do
  begin
    Inc(Result);
    IDList := NextPIDL(IDList);
  end;
end;

//create an ItemIDList object
function CreatePIDL(Size: Integer): PItemIDList;
var
Malloc: IMalloc;
begin
  OleCheck(SHGetMalloc(Malloc));
  
  Result := Malloc.Alloc(Size);
  if Assigned(Result) then
  FillChar(Result^, Size, 0);
end;

function CopyPIDL(IDList: PItemIDList): PItemIDList;
var
Size: Integer;
begin
  Size := GetPIDLSize(IDList);
  Result := CreatePIDL(Size);
  if Assigned(Result) then
  CopyMemory(Result, IDList, Size);
end;

//get the last ItemID from AbsoluteID
function RelativeFromAbsolute(AbsoluteID: PItemIDList): PItemIDList;
begin
  Result := AbsoluteID;
  while GetItemCount(Result) > 1 do
  Result := NextPIDL(Result);
  Result := CopyPIDL(Result);
end;

//remove the last ID from IDList
procedure StripLastID(IDList: PItemIDList);
var
MarkerID: PItemIDList;
begin
  MarkerID := IDList;
  if Assigned(IDList) then
  begin
    while IDList.mkid.cb <> 0 do
    begin
      MarkerID := IDList;
      IDList := NextPIDL(IDList);

判断文件夹是否共享的DELPHI代码》由第二电脑网原创提供,转载请注明:http://www.002pc.com/master/College/Language/Delphi/12422.html


关键字:

关于《判断文件夹是否共享的DELPHI代码》文章的评论

站内搜索: 高级搜索

热门搜索: Windows style 系统 tr IP QQ CPU 安装 function 注册 if td