FolderUnit.pas 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. unit FolderUnit;
  2. interface
  3. uses
  4. Classes, ComCtrls;
  5. type
  6. TFolder = class(TObject)
  7. private
  8. FTreeItem: TTreeNode;
  9. function GetFolderName: string;
  10. procedure SetFolderName(const Value: string);
  11. function GetParent: TFolder;
  12. function GetPath: string;
  13. public
  14. property Parent: TFolder read GetParent;
  15. published
  16. property FolderName: string read GetFolderName write SetFolderName;
  17. property Path: string read GetPath;
  18. property TreeItem: TTreeNode read FTreeItem write FTreeItem;
  19. end;
  20. implementation
  21. uses
  22. UtilsDos;
  23. { TFolder }
  24. function TFolder.GetFolderName: string;
  25. begin
  26. if Assigned (TreeItem) then
  27. Result := TreeItem.Text
  28. else
  29. Result := '';
  30. end;
  31. function TFolder.GetParent: TFolder;
  32. var
  33. ParentItem: TTreeNode;
  34. begin
  35. Result := nil;
  36. if Assigned (TreeItem) then begin
  37. ParentItem := TreeItem.Parent;
  38. if Assigned (ParentItem) and Assigned (ParentItem.Data) and (TObject (ParentItem.Data) is TFolder) then
  39. Result := ParentItem.Data;
  40. end;
  41. end;
  42. function TFolder.GetPath: string;
  43. var
  44. P: TFolder;
  45. begin
  46. P := Parent;
  47. if Assigned (P) and (Length (P.FolderName) > 0) then begin
  48. Result := P.Path;
  49. if Length (Result) > 0 then
  50. Result := WithBackslash (Result) + FolderName
  51. else
  52. Result := FolderName;
  53. end else
  54. Result := FolderName;
  55. end;
  56. procedure TFolder.SetFolderName(const Value: string);
  57. begin
  58. if Assigned (TreeItem) then
  59. TreeItem.Text := Value;
  60. end;
  61. end.