FolderUnit.pas 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. {
  2. TIGCC IDE
  3. Copyright (C) 2000-2004 Sebastian Reichelt
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2, or (at your option)
  7. any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software Foundation,
  14. Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  15. }
  16. unit FolderUnit;
  17. interface
  18. uses
  19. Classes, ComCtrls;
  20. type
  21. TFolder = class(TObject)
  22. private
  23. FTreeItem: TTreeNode;
  24. function GetFolderName: string;
  25. procedure SetFolderName(const Value: string);
  26. function GetParent: TFolder;
  27. function GetPath: string;
  28. public
  29. property Parent: TFolder read GetParent;
  30. published
  31. property FolderName: string read GetFolderName write SetFolderName;
  32. property Path: string read GetPath;
  33. property TreeItem: TTreeNode read FTreeItem write FTreeItem;
  34. end;
  35. implementation
  36. uses
  37. UtilsDos;
  38. { TFolder }
  39. function TFolder.GetFolderName: string;
  40. begin
  41. if Assigned (TreeItem) then
  42. Result := TreeItem.Text
  43. else
  44. Result := '';
  45. end;
  46. function TFolder.GetParent: TFolder;
  47. var
  48. ParentItem: TTreeNode;
  49. begin
  50. Result := nil;
  51. if Assigned (TreeItem) then begin
  52. ParentItem := TreeItem.Parent;
  53. if Assigned (ParentItem) and Assigned (ParentItem.Data) and (TObject (ParentItem.Data) is TFolder) then
  54. Result := ParentItem.Data;
  55. end;
  56. end;
  57. function TFolder.GetPath: string;
  58. var
  59. P: TFolder;
  60. begin
  61. P := Parent;
  62. if Assigned (P) and (Length (P.FolderName) > 0) then begin
  63. Result := P.Path;
  64. if Length (Result) > 0 then
  65. Result := WithBackslash (Result) + FolderName
  66. else
  67. Result := FolderName;
  68. end else
  69. Result := FolderName;
  70. end;
  71. procedure TFolder.SetFolderName(const Value: string);
  72. begin
  73. if Assigned (TreeItem) then
  74. TreeItem.Text := Value;
  75. end;
  76. end.