Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Catalog · How the catalog works

Random project

CodeEdit

Code Editor Component For Delphi

View on GitHub

Anyone may press Interesting, signed in or not. It helps others find this project.

Member rating

No ratings yet.

Sign in to rate this project.

README

CodeEdit

Native Delphi/VCL code editor component. No third-party dependencies — just the RTL and VCL.

Released under the MIT License. If you use CodeEdit in your project, attribution is appreciated.

Features

  • Owner-drawn editor with gutter, line numbers, and theme-aware painting (follows the active VCL style, with an OnResolveTheme hook for other skinning systems)
  • Pluggable syntax highlighting with ten bundled languages and correct multi-line constructs (block comments, template literals, triple-quoted strings)
  • Code completion and signature help driven by a provider component
  • Code templates on Ctrl+J — per-language snippet expansion with caret placeholder; user templates layer on top of the app's built-in set (JSON persisted, editable in a built-in dialog, overrides by name)
  • Find/replace panel with match-case, whole-word, and regex modes; results stay in sync while editing
  • Multi-caret editing (Ctrl+D / Ctrl+Shift+L), word navigation, indent/unindent, line commenting
  • Breakpoints, execution-line arrow, executable-line dots, and error/warning line markers for debugger hosts — design-time editable, 1-based, edit-tracked
  • Undo/redo with typing coalescing that also restores breakpoints, execution line, and the Modified flag
  • Word wrap (optionally indenting continuation rows), minimap (with hover preview), styled scrollbars, bracket matching, occurrence highlighting
  • Printing: TCodeEditorPrinter with syntax colours, line numbers, header/footer macros, word wrap, print dialog and a built-in preview
  • User settings: TCodeEditorSettings keeps an editor's preferences under HKCU and shows an options dialog with live preview and import/export

Documentation

  • TCodeEditor reference — properties, methods, events, options, theming, full keyboard table
  • Highlighters — bundled languages, token model, writing your own highlighter, the multi-line state contract
  • Completion and signature help — provider API and context records
  • Code templates — Ctrl+J templates, the provider component, placeholder syntax, and the template editor dialog
  • Breakpoints and line markers — the debugger-host surface
  • Printing — TCodeEditorPrinter, options, macros, preview, drawing pages on your own canvas
  • Settings — TCodeEditorSettings, the HKCU persistence, the options dialog and import/export

Units

  • Source\CodeEdit.Editor.pas — TCodeEditor
  • Source\CodeEdit.Completion.pas — completion/signature providers and a keyword provider
  • Source\CodeEdit.Highlighter.pas — token model and highlighters for Delphi, JavaScript, SQL, Tungli, Batch (BAT/CMD), PowerShell, INI, YAML, and Python
  • Source\CodeEdit.Templates.pas — code template model and TCodeTemplateProvider
  • Source\CodeEdit.TemplateEditorDlg.pas — runtime/design-time template editor dialog
  • Source\CodeEdit.Print.pas — TCodeEditorPrinter and the print preview
  • Source\CodeEdit.Settings.pas — TCodeEditorSettings (HKCU persistence, import/export) and Source\CodeEdit.SettingsDlg.pas — its options dialog form
  • Source\CodeEdit.DevExpressTheme.pas — optional DevExpress skin bridge (add to apps directly; not part of the package)
  • Source\CodeEdit.Register.pas — registers everything on the CodeEdit palette page
  • Packages\CodeEditVcl.dpk — design-time package
  • Samples\VclDemo — demo applications (CodeEditDemo, CodeEditDemo2)
  • Samples\DxDemo — CodeEditDemo2 with DevExpress skins: skin picker, the skin bridge keeping the editor's colours in step, and the settings dialog's "Follow the DevExpress skin" choice (needs DevExpress VCL)
  • Tests\TestHighlighterState.dpr — console regression test for the multi-line tokenizer state

Quick start

Install Packages\CodeEditVcl.dpk (or just add Source to your library path), then drop a TCodeEditor and a highlighter on a form:

pascal
CodeEditor1.Highlighter := DelphiCodeHighlighter1;
CodeEditor1.Lines.LoadFromFile('Demo.pas');

Completion is one event away:

pascal
CodeEditor1.CompletionProvider := KeywordCompletionProvider1;
KeywordCompletionProvider1.Keywords.CommaText := 'begin,end,procedure,function';

Caret and scroll positions are 0-based; breakpoints, line markers, and ExecutionLine are 1-based to match the gutter. See the editor reference for the details.

Host integration in five lines

pascal
CodeEditor1.Options.LineCommentPrefix := '--';        // language-specific
CodeEditor1.OnCaretChange := UpdateStatusBar;          // 0-based position
CodeEditor1.OnBreakpointsChanged := SyncInterpreter;   // 1-based lines
CodeEditor1.ExecutionLine := Interpreter.CurrentLine;  // current statement
CodeEditor1.Modified := False;                         // after saving

Most settings are published properties, so form storage systems persist the editor directly.

Roadmap

  • Per-breakpoint enabled state and conditions
  • Diff-based undo storage and virtualized rendering for very large files
  • IME composition-window positioning
  • Diagnostics API (squiggles) and symbol navigation hooks
  • Possible Delphi 7 compatibility pass (the code currently uses unit namespaces, generics, character helpers, and VCL styles)

Changelog

See CHANGELOG.md.