Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[submodule "Modules/VirtualTreeView"]
path = Modules/VirtualTreeView
url = https://github.com/TurboPack/VirtualTreeView.git
[submodule "Modules/SynEdit"]
path = Modules/SynEdit
url = https://github.com/TurboPack/SynEdit.git
133 changes: 133 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
# CLAUDE.md

This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.

## Project Overview

Delphi Unit Dependency Scanner (DUDS) is a Windows desktop application built with Delphi that parses Delphi projects and builds a unit file hierarchy. It analyzes unit dependencies, detects circular references, and can export relationships in multiple formats (XML, Gephi CSV, GraphML). The tool also supports unit renaming using regex expressions.

## Build Instructions

### Prerequisites

- Delphi 11 or later (originally built with Delphi Tokyo, currently compiled under Delphi 11)
- Target platform: Win32 and Win64
- Required 3rd party libraries:
- **VirtualTreeView** (TurboPack)
- **SynEdit** (TurboPack)

**Derivative Work Note:** This repository includes these libraries as Git submodules in `Modules/` directory.

**Installation Steps:**
1. Initialize submodules: `git submodule update --init --recursive`
2. Install VirtualTreeView packages from `Modules/VirtualTreeView/Packages/11AndAbove/Delphi/`:
- Build `VirtualTreesDR.dproj` (Runtime)
- Build and Install `VirtualTreesDD.dproj` (Designtime)
3. Install SynEdit packages from `Modules/SynEdit/Packages/11AndAbove/Delphi/`:
- Build `SynEditDR.dproj` (Runtime)
- Build and Install `SynEditDD.dproj` (Designtime)

Alternatively, install via GetIt Package Manager in the Delphi IDE (requires internet connection).

### Building

1. Open `Source/DependencyScanner.dproj` in the Delphi IDE
2. Select target platform (Win32 or Win64)
3. Build configuration:
- **Debug**: Standard debug build with symbols
- **Release**: Optimized production build
4. Build output locations:
- Executable: `..\Bin\Duds\$(Platform)\$(Config)`
- DCU files: `$(BDSUSERDIR)\DCU\Duds\$(Platform)\`

The main project file is `Source/DependencyScanner.dpr`. Build directly from the IDE (Project → Build) or use MSBuild if needed.

## Architecture

### Core Components

#### Parsing System
The Pascal source code parser is the heart of DUDS:

- **Tokeniser** (`Duds.Common.Parser.Pascal.Tokeniser.pas`): Breaks Pascal source into tokens
- **Parser** (`Duds.Common.Parser.Pascal.pas`): Implements `TUnitInfo` and `TUsedUnitInfo` classes that parse .pas, .dpr, .dpk files to extract:
- Unit names and file types (PAS/DPR/DPK/LIB)
- Uses clauses (interface vs implementation sections)
- Unit dependency relationships

#### Data Model
The application uses interface-based design for the core data structures:

- **Interfaces** (`Duds.Common.Interfaces.pas`): Defines `IUnitInfo` and `IUsedUnitInfo` interfaces
- **Implementation** (`Duds.Common.Parser.Pascal.pas`): `TUnitInfo` and `TUsedUnitInfo` implement these interfaces
- **Types** (`Duds.Common.Types.pas`): Core enums including:
- `TDelphiFileType`: ftPAS, ftDPR, ftDPK, ftLIB
- `TUsedUnitType`: utInterface, utImplementation, utContains
- `TCircularRelationshipType`: crNone, crSemiCircular, crCircular

#### Dependency Graph
- **Data Structure** (`Duds.Common.Classes.pas`):
- `TDelphiFile`: Wraps `IUnitInfo` with metadata (usage count, search path status, tree node reference)
- `TNodeObject`: Links tree nodes to `TDelphiFile` instances, tracks circular references
- Tree structure maintained via VirtualTreeView's node system
- **Main Form** (`Duds.Vcl.Form.Main.pas`): Orchestrates scanning, builds dependency tree, manages UI state

#### Settings Management
- **Project Settings** (`TProjectSettings` in `Duds.Common.Classes.pas`): Root files, search paths, unit scope names, linking preferences
- **Environment Settings** (`TEnvironmentSettings`): UI state, window positions, user preferences
- Both use INI file persistence via `TBaseSettings` abstract class

### UI Organization

The main form (`Duds.Vcl.Form.Main.pas`) uses a split-pane layout:

- **Left**: Tree view showing hierarchical unit dependencies
- **Right**: Tab control with:
- **Tree tab**: Parent/selected file source views (SynEdit with Pascal syntax highlighting)
- **List tab**: Flat list views of units with search filtering
- **Stats tab**: Dependency statistics
- **Bottom**: Status log (VirtualTreeView) showing scan progress and errors

All tree/list views use VirtualTreeView for performance with large codebases.

### Delphi Integration

`Duds.Common.Delphi.pas` provides registry-based Delphi IDE detection:
- Reads Delphi installation paths from registry (versions 15-17 supported in code)
- Extracts library paths and environment variables
- Evaluates Delphi macros in paths (e.g., `$(BDS)`)

This allows DUDS to automatically discover standard Delphi units and library locations.

### Export Formats

The application can export dependency graphs to:
- **XML**: Custom XML format
- **Gephi CSV**: Node/edge format for Gephi graph visualization
- **GraphML**: Standard graph interchange format

### Unit Renaming

DUDS supports bulk unit renaming with regex:
- Scans files for unit name occurrences
- Supports "dummy run" mode to preview changes
- Can optionally rename history backup files
- Updates both unit declarations and uses clauses

## Key Design Patterns

- **Interface-based design**: Core data structures use interfaces (`IUnitInfo`, `IUsedUnitInfo`) for flexibility
- **Node data pattern**: VirtualTreeView nodes store indices into `TDelphiFile` list rather than full objects
- **Settings abstraction**: `TBaseSettings` base class with abstract `DoSaveToIniFile`/`DoLoadFromIniFile` methods
- **Helper classes**: IniFile helper (`Duds.Common.Helper.IniFile.pas`) extends TIniFile with bulk string operations

## File Organization

All source files use the `Duds.` prefix namespace:
- `Duds.Common.*`: Platform-independent business logic
- `Duds.Vcl.*`: VCL-specific UI components
- Forms follow pattern: `Duds.Vcl.Form.[FormName].pas`

## License

Dual-licensed under Mozilla Public License 2.0 or GNU LGPL 2.1+. Originally released as freeware, open-sourced in July 2017 by Easy-IP AS.
1 change: 1 addition & 0 deletions Modules/SynEdit
Submodule SynEdit added at 5659ac
1 change: 1 addition & 0 deletions Modules/VirtualTreeView
Submodule VirtualTreeView added at a4b671
45 changes: 44 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,48 @@ DUDS is built with Delphi Tokyo, but will proabably compile with all compilers a
* VirtualTreeView
* SynEdit

Cheers,
## Derivative Work Addition: Git Submodules
**Note:** This fork includes the required libraries as Git submodules in the `Modules/` directory (added as derivative work, not part of the original release).

### Step 1: Initialize Submodules

After cloning this repository, initialize the submodules:
```bash
git submodule update --init --recursive
```

The submodules reference the official TurboPack repositories:
* **VirtualTreeView**: [TurboPack/VirtualTreeView](https://github.com/TurboPack/VirtualTreeView)
* **SynEdit**: [TurboPack/SynEdit](https://github.com/TurboPack/SynEdit)

### Step 2: Install VirtualTreeView Package

1. Open in Delphi IDE: `Modules/VirtualTreeView/Packages/11AndAbove/Delphi/VirtualTreesDR.dproj`
2. Click **Project → Build All**
3. Close the project
4. Open: `Modules/VirtualTreeView/Packages/11AndAbove/Delphi/VirtualTreesDD.dproj`
5. Click **Project → Build All**
6. Click **Project → Install**
7. Confirm the installation

### Step 3: Install SynEdit Package

1. Open in Delphi IDE: `Modules/SynEdit/Packages/11AndAbove/Delphi/SynEditDR.dproj`
2. Click **Project → Build All**
3. Close the project
4. Open: `Modules/SynEdit/Packages/11AndAbove/Delphi/SynEditDD.dproj`
5. Click **Project → Build All**
6. Click **Project → Install**
7. Confirm the installation

### Step 4: Build DUDS

1. Open: `Source/DependencyScanner.dproj`
2. Press **Ctrl+F9** (Compile) or **F9** (Run)

**Note:** For older Delphi versions (Tokyo, Rio, Sydney), use the corresponding package folders in `Modules/VirtualTreeView/Packages/` and `Modules/SynEdit/Packages/`.

---

Cheers,
Paul.
Loading