Plugin Contract

This page covers ITcPlugin and ITcEnumExtensionsCallback, the two core interfaces that define the public TonCut Desktop plugin contract. It also summarizes how TonCut Desktop discovers, loads, and gates a plugin; the full host behaviour is on Lifecycle & Capabilities.

Contract overview

ITcPlugin mixes metadata, lifecycle hooks, configuration, file handling, result export, and plot-related callbacks in a single interface. Every method must be implemented, because every vtable slot is part of the contract, but TonCut calls a feature callback only when the matching flag is set.

What TonCut Desktop does with a plugin:

  1. It scans the Plugins folder next to TonCut.exe, including subfolders, for lowercase .plg files.
  2. It resolves the exported TcpInitializeV2 and keeps the returned plugin until it unloads it. It never calls Initialize; the entry point does.
  3. It activates the plugin only when EngineVersion equals its own engine version exactly (shown in the header badge). Otherwise the plugin is listed as Not compatible.
  4. It builds its file dialog filters from EnumExtensions.
  5. It calls Finalize, releases the plugin, and unloads the DLL at shutdown and before a plugin update.

Core contract members

property Name: WideString read GetName;
property EngineVersion: Integer read GetEngineVersion;
property Features: TTcpFeatures read GetFeatures;

function Initialize(const aRegRoot: WideString; aLanguageId: Integer; aTonCut: ITonCut): TTcpResult; safecall;
function EnumExtensions(aType: TTcpExtensionType; aEnumCb: ITcEnumExtensionsCallback): TTcpResult; safecall;
function IsMyFile(const aFileName: WideString): TTcpResult; safecall;

In a C# plugin the native C++ shim implements these members; managed code never implements ITcPlugin.

Entrypoint rules

The entrypoint itself is not declared in a public interface unit, but the runtime rule is explicit:

TcpInitializeV2 signature

type
  TTcPluginInitialize = function(
    const aRegRoot: PChar;
    aLanguageId: Integer;
    aTonCut: ITonCut
  ): ITcPlugin; stdcall;

Your export must use the name TcpInitializeV2 and be callable through stdcall. Delphi sees it as returning an ITcPlugin, while native C++ implementations must accept that interface result as a hidden first ITcPlugin** parameter.

MSVC decorates this export as _TcpInitializeV2@16; a module definition file must export it as plain TcpInitializeV2. A C# plugin uses this same native entry point in its C++ shim. See ABI & Marshalling for the Delphi .dpr and the MSVC .def file.

Interfaces

Declarations are shown in Pascal and, where the SDK's generated language-support manifest lists the member for C++, in C++; the build fails if that manifest no longer matches TonCutPluginSdk.hpp. There is no C# declaration: C# plugins are native-shim-only, so a C++ shim owns every interface on this page. Methods are listed with their accessors folded into properties; open Vtable order for the exact slot sequence, and see ABI and marshalling for type sizes and ownership rules.

ITcPlugin

The interface every plugin implements. TonCut obtains it from the exported TcpInitializeV2 function, reads its metadata and feature flags, and calls its callbacks from user actions.

IID
None declared. The interface has no GUID, so it cannot be obtained through QueryInterface; it is only passed and returned directly.
Parent
IUnknown (implicit: a Delphi interface without a parent is IUnknown)
Unit
uITcPlugin
Vtable order (31 methods, slots 3 to 33, after the three IUnknown slots)
  1. function GetEngineVersion(): Integer;
  2. function GetName(): WideString;
  3. function GetVersion(): TTcpVersion;
  4. function GetTitle(): WideString;
  5. function GetProfessional(): Boolean;
  6. function GetRegRoot(): WideString;
  7. function GetLanguageId(): Integer;
  8. procedure SetLanguageId(aLanguageId: Integer);
  9. function GetUiScale(): Single;
  10. procedure SetUiScale(aScale: Single);
  11. function GetTonCut(): ITonCut;
  12. function GetFeatures(): TTcpFeatures;
  13. function GetPlotterInfo: ITcPlotterInfo;
  14. function Initialize(const aRegRoot: WideString; aLanguageId: Integer; aTonCut: ITonCut): TTcpResult;
  15. function Finalize(): TTcpResult;
  16. function Configure(aWindow: THandle): TTcpResult;
  17. function About(aWindow: THandle): TTcpResult;
  18. function LoadConfig(const aKey, aVersion: WideString): TTcpResult;
  19. function SaveConfig(const aKey: WideString): TTcpResult;
  20. function BackupConfig(var aBackup: WideString): TTcpResult;
  21. function RestoreConfig(const aBackup: WideString; aScope: TConfigurationParts): TTcpResult;
  22. function EnumExtensions(aType: TTcpExtensionType; aEnumCb: ITcEnumExtensionsCallback): TTcpResult;
  23. function IsMyFile(const aFileName: WideString): TTcpResult;
  24. function LoadFile(aWindow: THandle; const aFileName: WideString; aDevices: IDevices; aMaterials: IMaterials; aBands: IBands; aProjects: IProjects; aFormats: IFormats; aSheets: ISheets): TTcpResult;
  25. function SaveFile(aWindow: THandle; const aFileName: WideString; const aFormats: IFormats; const aSheets: ISheets): TTcpResult;
  26. function SaveResult(aWindow: THandle; const aFileName: WideString; const aSolutionSheet: ISolutionSheet): TTcpResult;
  27. function BatchSaveResult(aWindow: THandle; aSaveTarget: TTcpSaveTarget; const aPath: WideString; const aSolution: ISolution): TTcpResult;
  28. function Plot(aWindow: THandle; const aSolutionSheet: ISolutionSheet): TTcpResult;
  29. function BatchPlot(aWindow: THandle; const aSolution: ISolution): TTcpResult;
  30. function SavePlot(aWindow: THandle; const aFileName: WideString; const aSolutionSheet: ISolutionSheet): TTcpResult;
  31. function BatchSavePlot(aWindow: THandle; aSaveTarget: TTcpSaveTarget; const aPath: WideString; const aSolution: ISolution): TTcpResult;

Properties

  • Property name
    EngineVersion
    Type
    Integer
    Description

    Engine version the plugin was built for. Return cEngineVersion from the SDK you compiled against. TonCut activates the plugin only when it equals its own engine version exactly; otherwise the plugin is listed as Not compatible and never called for work.

    Declaration

    property EngineVersion: Integer read GetEngineVersion;
  • Property name
    Name
    Type
    WideString
    Description

    Stable plugin name. It must be unique among installed plugins (a duplicate stops TonCut from loading the remaining plugins) and plain ASCII (TonCut stores it as an ANSI short string). A device Driver refers to it, and the configuration backup file is named after it.

    Declaration

    property Name: WideString read GetName;
  • Property name
    Version
    Type
    TTcpVersion
    Description

    Plugin version: four 16-bit fields (major, minor, build, revision) packed from the most significant end. TonCut shows it as a.b.c.d.

    Declaration

    property Version: TTcpVersion read GetVersion;
  • Property name
    Title
    Type
    WideString
    Description

    Human-readable plugin title shown in Options and dialogs.

    Declaration

    property Title: WideString read GetTitle;
  • Property name
    RegRoot
    Type
    WideString
    Description

    Plugin-specific registry root supplied by the host.

    Declaration

    property RegRoot: WideString read GetRegRoot;
  • Property name
    LanguageId
    Type
    Integer
    Description

    User-interface language. TonCut sets it on every plugin state change and when the user switches language.

    Declaration

    property LanguageId: Integer read GetLanguageId write SetLanguageId;
  • Property name
    Professional
    Type
    Boolean
    Description

    When true, import, export, save-result, plot, and accept-solution export through this plugin require the Professional edition.

    Declaration

    property Professional: Boolean read GetProfessional;
  • Property name
    UiScale
    Type
    Single
    Description

    User-interface scale factor. TonCut sets it once while loading the plugin.

    Declaration

    property UiScale: Single read GetUiScale write SetUiScale;
  • Property name
    TonCut
    Type
    ITonCut
    Description

    Host service object supplied during plugin initialization.

    Declaration

    property TonCut: ITonCut read GetTonCut;
  • Property name
    Features
    Type
    Description

    Feature flags. They enable TonCut commands and buttons; file dialog filters come only from EnumExtensions. Any result or plot save flag makes PlotterInfo mandatory.

    Declaration

    property Features: TTcpFeatures read GetFeatures;
  • Property name
    PlotterInfo
    Type
    ITcPlotterInfo
    Description

    Plotter descriptor implemented by the plugin. It must be a valid object whenever any result or plot save flag is set: TonCut copies it, and a nil result disables the plugin. When a device Driver names this plugin, TonCut takes the plugin-controlled device settings from it.

    Declaration

    property PlotterInfo: ITcPlotterInfo read GetPlotterInfo;

Methods

  • Method name
    Initialize()
    Type
    Description

    Initialize the plugin with its registry root, user-interface language, and host service object. TonCut never calls this method: the TcpInitializeV2 entry point must create the plugin, call Initialize itself, and return the plugin only when it returned cprOK.

    Declaration

    function Initialize(const aRegRoot: WideString; aLanguageId: Integer; aTonCut: ITonCut): TTcpResult; safecall;
    Parameters
    aRegRootconst
    WideString
    Plugin-specific registry root supplied by the host.
    aLanguageId
    Integer
    Current host language identifier.
    aTonCut
    Shared host service interface.
    Returns
    TonCut plugin result code used to report success, failure, cancellation, or file-match state.
  • Method name
    Finalize()
    Type
    Description

    Release everything the plugin holds, including ITonCut. TonCut calls it at shutdown and before a plugin update, then releases the plugin and unloads the DLL immediately; every object the plugin created must reach a reference count of zero by then.

    Declaration

    function Finalize(): TTcpResult; safecall;
    Returns
    TonCut plugin result code used to report success, failure, cancellation, or file-match state.
  • Method name
    Configure()
    Type
    Description

    Show the plugin settings, owned by aWindow. Called only when feConfigure is advertised. The result is ignored.

    Declaration

    function Configure(aWindow: THandle): TTcpResult; safecall;
    Parameters
    aWindow
    THandle
    Owner window for any dialog the plugin shows. It is not always the main form: for example the input frame in LoadFile and the modal Save results dialog in the result callbacks.
    Returns
    TonCut plugin result code used to report success, failure, cancellation, or file-match state.
  • Method name
    About()
    Type
    Description

    Show information about the plugin, owned by aWindow. Called only when feAbout is advertised. The result is ignored.

    Declaration

    function About(aWindow: THandle): TTcpResult; safecall;
    Parameters
    aWindow
    THandle
    Owner window for any dialog the plugin shows. It is not always the main form: for example the input frame in LoadFile and the modal Save results dialog in the result callbacks.
    Returns
    TonCut plugin result code used to report success, failure, cancellation, or file-match state.
  • Method name
    LoadConfig()
    Type
    Description

    Load the plugin configuration. TonCut calls it while loading the plugin, except on the first run (no registry key yet) and for incompatible plugins. The result is ignored.

    Declaration

    function LoadConfig(const aKey: WideString; const aVersion: WideString): TTcpResult; safecall;
    Parameters
    aKeyconst
    WideString
    Configuration key selected by the host.
    aVersionconst
    WideString
    Configuration version tag supplied by the host.
    Returns
    TonCut plugin result code used to report success, failure, cancellation, or file-match state.
  • Method name
    SaveConfig()
    Type
    Description

    Persist plugin configuration to host-managed storage.

    Declaration

    function SaveConfig(const aKey: WideString): TTcpResult; safecall;
    Parameters
    aKeyconst
    WideString
    Configuration key selected by the host.
    Returns
    TonCut plugin result code used to report success, failure, cancellation, or file-match state.
  • Method name
    BackupConfig()
    Type
    Description

    Serialize plugin configuration into a backup payload.

    Declaration

    function BackupConfig(var aBackup: WideString): TTcpResult; safecall;
    Parameters
    aBackupvar
    WideString
    Serialized configuration backup payload. Passed by reference and may be updated by the callee.
    Returns
    TonCut plugin result code used to report success, failure, cancellation, or file-match state.
  • Method name
    RestoreConfig()
    Type
    Description

    Restore plugin configuration from a backup payload for the selected scopes.

    Declaration

    function RestoreConfig(const aBackup: WideString; aScope: TConfigurationParts): TTcpResult; safecall;
    Parameters
    aBackupconst
    WideString
    Serialized configuration backup payload.
    aScope
    Configuration parts to restore from the backup payload.
    Returns
    TonCut plugin result code used to report success, failure, cancellation, or file-match state.
  • Method name
    EnumExtensions()
    Type
    Description

    Register the file dialog filters for the requested extension type. Call aEnumCb.Invoke once per filter, with the extension including its leading dot (.csv), and only during this call. TonCut calls it while loading the plugin, once for each extension type. The result is ignored.

    Declaration

    function EnumExtensions(aType: TTcpExtensionType; aEnumCb: ITcEnumExtensionsCallback): TTcpResult; safecall;
    Parameters
    aType
    Extension category being enumerated.
    aEnumCb
    Callback to invoke once for each supported extension.

    Example

    function TTextPlugin.EnumExtensions(
      aType: TTcpExtensionType;
      aEnumCb: ITcEnumExtensionsCallback
    ): TTcpResult;
    begin
      case aType of
        etImport:
          aEnumCb.Invoke(etImport, '.txt', 'Delimited text');
        etExport:
          aEnumCb.Invoke(etExport, '.txt', 'Delimited text');
        etExportResults:
          aEnumCb.Invoke(etExportResults, '.txt', 'Delimited text');
      end;
    
      Result := cprOK;
    end;
    Returns
    TonCut plugin result code used to report success, failure, cancellation, or file-match state.
  • Method name
    IsMyFile()
    Type
    Description

    Check whether a file belongs to the plugin. TonCut asks only plugins with feImport, and only for the Open dialog’s All files filter, drag-and-drop, temporary-file import, and the command line; choosing the plugin’s own filter calls LoadFile directly. Return cprOK for a confirmed match, cprMaybe for a possible match, and cprNo otherwise.

    Declaration

    function IsMyFile(const aFileName: WideString): TTcpResult; safecall;
    Parameters
    aFileNameconst
    WideString
    Path of the file to inspect, load, or save.

    Example

    function TTextPlugin.IsMyFile(const aFileName: WideString): TTcpResult;
    var
      lines: TStringList;
      firstLine: string;
    begin
      if not SameText(ExtractFileExt(aFileName), '.txt') then
        Exit(cprNo);
    
      lines := TStringList.Create;
      try
        lines.LoadFromFile(aFileName, TEncoding.UTF8);
        if lines.Count = 0 then
          Exit(cprNo);
    
        firstLine := lines[0];
    
        if Pos(';', firstLine) > 0 then
          Exit(cprOK);
    
        if Pos(',', firstLine) > 0 then
          Exit(cprMaybe);
    
        Result := cprNo;
      finally
        lines.Free;
      end;
    end;
    Returns
    A file-match result. cprOK chooses the plugin at once. cprMaybe makes it a candidate; if no plugin returns cprOK, the last candidate in scan order is used. Any other value (return cprNo) skips the plugin.
  • Method name
    LoadFile()
    Type
    Description

    Import a file into new, empty staging collections. Create objects with the collections’ own CreateX methods and Add them. On cprOK TonCut opens its Import dialog and merges the staged data; on any other result, or an exception, everything staged is discarded.

    Declaration

    function LoadFile(aWindow: THandle; const aFileName: WideString; aDevices: IDevices; aMaterials: IMaterials; aBands: IBands; aProjects: IProjects; aFormats: IFormats; aSheets: ISheets): TTcpResult; safecall;
    Parameters
    aWindow
    THandle
    Owner window for any dialog the plugin shows. It is not always the main form: for example the input frame in LoadFile and the modal Save results dialog in the result callbacks.
    aFileNameconst
    WideString
    Path of the file to inspect, load, or save.
    aDevices
    Device collection supplied by the host. In LoadFile it is an empty staging collection, and devices added to it are ignored.
    aMaterials
    Material collection supplied by the host. In LoadFile it is a new, empty staging collection.
    aBands
    Band collection supplied by the host. In LoadFile it is a new, empty staging collection.
    aProjects
    Project collection supplied by the host. In LoadFile it is a new, empty staging collection.
    aFormats
    Piece collection: a new, empty staging collection in LoadFile, the live pieces in SaveFile. Do not keep it after the call.
    aSheets
    Stock collection: a new, empty staging collection in LoadFile, the live stock in SaveFile. Do not keep it after the call.
    Returns
    TonCut plugin result code used to report success, failure, cancellation, or file-match state.
  • Method name
    SaveFile()
    Type
    Description

    Export the live pieces and stock to a file. Any result other than cprOK, including cprCancel, makes TonCut show an "Error writing file" message.

    Declaration

    function SaveFile(aWindow: THandle; const aFileName: WideString; const aFormats: IFormats; const aSheets: ISheets): TTcpResult; safecall;
    Parameters
    aWindow
    THandle
    Owner window for any dialog the plugin shows. It is not always the main form: for example the input frame in LoadFile and the modal Save results dialog in the result callbacks.
    aFileNameconst
    WideString
    Path of the file to inspect, load, or save.
    aFormatsconst
    Piece collection: a new, empty staging collection in LoadFile, the live pieces in SaveFile. Do not keep it after the call.
    aSheetsconst
    Stock collection: a new, empty staging collection in LoadFile, the live stock in SaveFile. Do not keep it after the call.
    Returns
    TonCut plugin result code used to report success, failure, cancellation, or file-match state.
  • Method name
    SaveResult()
    Type
    Description

    Save one solution sheet. Called by Save one when feSaveResultToFile is advertised. A result other than cprOK is silent.

    Declaration

    function SaveResult(aWindow: THandle; const aFileName: WideString; const aSolutionSheet: ISolutionSheet): TTcpResult; safecall;
    Parameters
    aWindow
    THandle
    Owner window for any dialog the plugin shows. It is not always the main form: for example the input frame in LoadFile and the modal Save results dialog in the result callbacks.
    aFileNameconst
    WideString
    Path of the file to inspect, load, or save.
    aSolutionSheetconst
    Solution sheet being exported, saved, or plotted.
    Returns
    TonCut plugin result code used to report success, failure, cancellation, or file-match state.
  • Method name
    BatchSaveResult()
    Type
    Description

    Save the whole solution to the folder or file in aPath. TonCut marks as saved only the sheets on which the plugin set IsSaved. A result other than cprOK is silent.

    Declaration

    function BatchSaveResult(aWindow: THandle; aSaveTarget: TTcpSaveTarget; const aPath: WideString; const aSolution: ISolution): TTcpResult; safecall;
    Parameters
    aWindow
    THandle
    Owner window for any dialog the plugin shows. It is not always the main form: for example the input frame in LoadFile and the modal Save results dialog in the result callbacks.
    aSaveTarget
    Batch save target mode selected by the host.
    aPathconst
    WideString
    The folder the user chose when aSaveTarget is stFolder (the plugin picks the file names), otherwise the file the user chose, with the result extension already appended if the user typed none.
    aSolutionconst
    Entire solution being exported, saved, or plotted.
    Returns
    TonCut plugin result code used to report success, failure, cancellation, or file-match state.
  • Method name
    Plot()
    Type
    Description

    Run the plotting workflow for one solution sheet.

    Declaration

    function Plot(aWindow: THandle; const aSolutionSheet: ISolutionSheet): TTcpResult; safecall;
    Parameters
    aWindow
    THandle
    Owner window for any dialog the plugin shows. It is not always the main form: for example the input frame in LoadFile and the modal Save results dialog in the result callbacks.
    aSolutionSheetconst
    Solution sheet being exported, saved, or plotted.
    Returns
    TonCut plugin result code used to report success, failure, cancellation, or file-match state.
  • Method name
    BatchPlot()
    Type
    Description

    Run the plotting workflow for an entire solution.

    Declaration

    function BatchPlot(aWindow: THandle; const aSolution: ISolution): TTcpResult; safecall;
    Parameters
    aWindow
    THandle
    Owner window for any dialog the plugin shows. It is not always the main form: for example the input frame in LoadFile and the modal Save results dialog in the result callbacks.
    aSolutionconst
    Entire solution being exported, saved, or plotted.
    Returns
    TonCut plugin result code used to report success, failure, cancellation, or file-match state.
  • Method name
    SavePlot()
    Type
    Description

    Save plot output for one solution sheet. Called by Save one when feSavePlotToFile is advertised and feSaveResultToFile is not. A result other than cprOK is silent.

    Declaration

    function SavePlot(aWindow: THandle; const aFileName: WideString; const aSolutionSheet: ISolutionSheet): TTcpResult; safecall;
    Parameters
    aWindow
    THandle
    Owner window for any dialog the plugin shows. It is not always the main form: for example the input frame in LoadFile and the modal Save results dialog in the result callbacks.
    aFileNameconst
    WideString
    Path of the file to inspect, load, or save.
    aSolutionSheetconst
    Solution sheet being exported, saved, or plotted.
    Returns
    TonCut plugin result code used to report success, failure, cancellation, or file-match state.
  • Method name
    BatchSavePlot()
    Type
    Description

    Save plot output for the whole solution. Called by Save all when no batch-result flag is advertised. A result other than cprOK is silent.

    Declaration

    function BatchSavePlot(aWindow: THandle; aSaveTarget: TTcpSaveTarget; const aPath: WideString; const aSolution: ISolution): TTcpResult; safecall;
    Parameters
    aWindow
    THandle
    Owner window for any dialog the plugin shows. It is not always the main form: for example the input frame in LoadFile and the modal Save results dialog in the result callbacks.
    aSaveTarget
    Batch save target mode selected by the host.
    aPathconst
    WideString
    The folder the user chose when aSaveTarget is stFolder (the plugin picks the file names), otherwise the file the user chose, with the result extension already appended if the user typed none.
    aSolutionconst
    Entire solution being exported, saved, or plotted.
    Returns
    TonCut plugin result code used to report success, failure, cancellation, or file-match state.

ITcEnumExtensionsCallback

Callback sink used by TonCut while a plugin enumerates the file extensions it supports for import, export, or result export.

IID
{B17490F3-F2DA-4179-8D56-39B921D9C73A}
Parent
IUnknown
Unit
uITcEnumExtensionsCallback
Vtable order (1 methods, slots 3 to 3, after the three IUnknown slots)
  1. procedure Invoke(aType: TTcpExtensionType; const aExtension: WideString; const aName: WideString);

Methods

  • Method name
    Invoke()
    Type
    procedure
    Description

    Invoke the callback or event with the current payload.

    Declaration

    procedure Invoke(aType: TTcpExtensionType; const aExtension: WideString; const aName: WideString); safecall;
    Parameters
    aType
    Extension category being enumerated.
    aExtensionconst
    WideString
    Text value for extension.
    aNameconst
    WideString
    Text value for name.

Was this page helpful?