Delphi Code Refactoring

Identifies and applies safe refactoring techniques to Delphi and Object Pascal code.

48|12|Updated Mar 20, 2026
One-click install
npx skills add https://github.com/delphicleancode/delphi-spec-kit --skill delphi-code-refactoring
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: Delphi Code Refactoring
Source: https://github.com/delphicleancode/delphi-spec-kit/tree/main/.gemini/skills/refactoring
Command: npx skills add https://github.com/delphicleancode/delphi-spec-kit --skill delphi-code-refactoring

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Refactoring techniques for Object Pascal help maintain behavior while improving readability and maintainability, reducing technical debt.

Core Features & Use Cases

  • Extract Method, Extract Class, Guard Clauses, Replace Magic Numbers, Replace Conditional with Polymorphism, Introduce Parameter Object, Remove With, and Extract Interface to improve code quality and longevity.
  • Use cases include cleaning up legacy Delphi units, preparing code for new features, and ensuring safe refactoring with tests and clear patterns.
  • Real-world example: transform a monolithic procedure into cohesive components without changing external behavior.

Quick Start

Provide a refactoring plan for a given Delphi unit that preserves behavior while improving readability.

Frequently Asked Questions about Delphi Code Refactoring

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I refactor legacy Delphi code without changing its external behavior?

Refactor legacy Delphi code safely by applying incremental, test-driven techniques like Extract Method and Guard Clauses to preserve external behavior while improving readability and reducing technical debt.

What are common Object Pascal code smells and how do I remove them?

Object Pascal code smells include monolithic procedures and magic numbers. Remove them using structured patterns like Replace Magic Numbers, Extract Class, and Remove With to ensure clean, maintainable code.

How do I break down a large monolithic Delphi procedure into cohesive components?

Break down a monolithic Delphi procedure by applying Extract Method to isolate logic blocks and Extract Class to separate responsibilities, transforming it into cohesive components without altering functionality.

When should I use Replace Conditional with Polymorphism in Delphi refactoring?

Apply Guard Clauses in Object Pascal to replace deeply nested conditional checks with early exits, flattening the code structure and making the intended execution path immediately clear to readers.

Can I introduce a parameter object to simplify Delphi method signatures?

Introduce a Parameter Object in Delphi to consolidate multiple method parameters into a single structured object, simplifying method signatures and reducing dependencies during refactoring.