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:
- It scans the
Pluginsfolder next toTonCut.exe, including subfolders, for lowercase.plgfiles. - It resolves the exported
TcpInitializeV2and keeps the returned plugin until it unloads it. It never callsInitialize; the entry point does. - It activates the plugin only when
EngineVersionequals its own engine version exactly (shown in the header badge). Otherwise the plugin is listed as Not compatible. - It builds its file dialog filters from
EnumExtensions. - 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)
- function GetEngineVersion(): Integer;
- function GetName(): WideString;
- function GetVersion(): TTcpVersion;
- function GetTitle(): WideString;
- function GetProfessional(): Boolean;
- function GetRegRoot(): WideString;
- function GetLanguageId(): Integer;
- procedure SetLanguageId(aLanguageId: Integer);
- function GetUiScale(): Single;
- procedure SetUiScale(aScale: Single);
- function GetTonCut(): ITonCut;
- function GetFeatures(): TTcpFeatures;
- function GetPlotterInfo: ITcPlotterInfo;
- function Initialize(const aRegRoot: WideString; aLanguageId: Integer; aTonCut: ITonCut): TTcpResult;
- function Finalize(): TTcpResult;
- function Configure(aWindow: THandle): TTcpResult;
- function About(aWindow: THandle): TTcpResult;
- function LoadConfig(const aKey, aVersion: WideString): TTcpResult;
- function SaveConfig(const aKey: WideString): TTcpResult;
- function BackupConfig(var aBackup: WideString): TTcpResult;
- function RestoreConfig(const aBackup: WideString; aScope: TConfigurationParts): TTcpResult;
- function EnumExtensions(aType: TTcpExtensionType; aEnumCb: ITcEnumExtensionsCallback): TTcpResult;
- function IsMyFile(const aFileName: WideString): TTcpResult;
- function LoadFile(aWindow: THandle; const aFileName: WideString; aDevices: IDevices; aMaterials: IMaterials; aBands: IBands; aProjects: IProjects; aFormats: IFormats; aSheets: ISheets): TTcpResult;
- function SaveFile(aWindow: THandle; const aFileName: WideString; const aFormats: IFormats; const aSheets: ISheets): TTcpResult;
- function SaveResult(aWindow: THandle; const aFileName: WideString; const aSolutionSheet: ISolutionSheet): TTcpResult;
- function BatchSaveResult(aWindow: THandle; aSaveTarget: TTcpSaveTarget; const aPath: WideString; const aSolution: ISolution): TTcpResult;
- function Plot(aWindow: THandle; const aSolutionSheet: ISolutionSheet): TTcpResult;
- function BatchPlot(aWindow: THandle; const aSolution: ISolution): TTcpResult;
- function SavePlot(aWindow: THandle; const aFileName: WideString; const aSolutionSheet: ISolutionSheet): TTcpResult;
- 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
cEngineVersionfrom 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
Driverrefers 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 makesPlotterInfomandatory.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
nilresult disables the plugin. When a deviceDrivernames 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
TcpInitializeV2entry point must create the plugin, callInitializeitself, and return the plugin only when it returnedcprOK.Declaration
function Initialize(const aRegRoot: WideString; aLanguageId: Integer; aTonCut: ITonCut): TTcpResult; safecall;ParametersaRegRootconstWideStringPlugin-specific registry root supplied by the host.aLanguageIdIntegerCurrent host language identifier.ReturnsTonCut 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;ReturnsTonCut 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 whenfeConfigureis advertised. The result is ignored.Declaration
function Configure(aWindow: THandle): TTcpResult; safecall;ParametersaWindowTHandleOwner window for any dialog the plugin shows. It is not always the main form: for example the input frame inLoadFileand the modal Save results dialog in the result callbacks.ReturnsTonCut 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 whenfeAboutis advertised. The result is ignored.Declaration
function About(aWindow: THandle): TTcpResult; safecall;ParametersaWindowTHandleOwner window for any dialog the plugin shows. It is not always the main form: for example the input frame inLoadFileand the modal Save results dialog in the result callbacks.ReturnsTonCut 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;ParametersaKeyconstWideStringConfiguration key selected by the host.aVersionconstWideStringConfiguration version tag supplied by the host.ReturnsTonCut 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;ParametersaKeyconstWideStringConfiguration key selected by the host.ReturnsTonCut 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;ParametersaBackupvarWideStringSerialized configuration backup payload. Passed by reference and may be updated by the callee.ReturnsTonCut 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;ParametersaBackupconstWideStringSerialized configuration backup payload.aScopeConfiguration parts to restore from the backup payload.ReturnsTonCut 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.Invokeonce 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;ParametersaTypeExtension category being enumerated.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;ReturnsTonCut 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 callsLoadFiledirectly. ReturncprOKfor a confirmed match,cprMaybefor a possible match, andcprNootherwise.Declaration
function IsMyFile(const aFileName: WideString): TTcpResult; safecall;ParametersaFileNameconstWideStringPath 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;ReturnsA file-match result.cprOKchooses the plugin at once.cprMaybemakes it a candidate; if no plugin returnscprOK, the last candidate in scan order is used. Any other value (returncprNo) skips the plugin.
- Method name
- LoadFile()
- Type
- Description
Import a file into new, empty staging collections. Create objects with the collections’ own
CreateXmethods andAddthem. OncprOKTonCut 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;ParametersaWindowTHandleOwner window for any dialog the plugin shows. It is not always the main form: for example the input frame inLoadFileand the modal Save results dialog in the result callbacks.aFileNameconstWideStringPath of the file to inspect, load, or save.aDevicesDevice collection supplied by the host. InLoadFileit is an empty staging collection, and devices added to it are ignored.aMaterialsMaterial collection supplied by the host. InLoadFileit is a new, empty staging collection.aBandsBand collection supplied by the host. InLoadFileit is a new, empty staging collection.aProjectsProject collection supplied by the host. InLoadFileit is a new, empty staging collection.aFormatsPiece collection: a new, empty staging collection inLoadFile, the live pieces inSaveFile. Do not keep it after the call.aSheetsStock collection: a new, empty staging collection inLoadFile, the live stock inSaveFile. Do not keep it after the call.ReturnsTonCut 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, includingcprCancel, makes TonCut show an "Error writing file" message.Declaration
function SaveFile(aWindow: THandle; const aFileName: WideString; const aFormats: IFormats; const aSheets: ISheets): TTcpResult; safecall;ParametersaWindowTHandleOwner window for any dialog the plugin shows. It is not always the main form: for example the input frame inLoadFileand the modal Save results dialog in the result callbacks.aFileNameconstWideStringPath of the file to inspect, load, or save.aFormatsconstPiece collection: a new, empty staging collection inLoadFile, the live pieces inSaveFile. Do not keep it after the call.aSheetsconstStock collection: a new, empty staging collection inLoadFile, the live stock inSaveFile. Do not keep it after the call.ReturnsTonCut 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
feSaveResultToFileis advertised. A result other thancprOKis silent.Declaration
function SaveResult(aWindow: THandle; const aFileName: WideString; const aSolutionSheet: ISolutionSheet): TTcpResult; safecall;ParametersaWindowTHandleOwner window for any dialog the plugin shows. It is not always the main form: for example the input frame inLoadFileand the modal Save results dialog in the result callbacks.aFileNameconstWideStringPath of the file to inspect, load, or save.ReturnsTonCut 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 setIsSaved. A result other thancprOKis silent.Declaration
function BatchSaveResult(aWindow: THandle; aSaveTarget: TTcpSaveTarget; const aPath: WideString; const aSolution: ISolution): TTcpResult; safecall;ParametersaWindowTHandleOwner window for any dialog the plugin shows. It is not always the main form: for example the input frame inLoadFileand the modal Save results dialog in the result callbacks.aSaveTargetBatch save target mode selected by the host.aPathconstWideStringThe folder the user chose whenaSaveTargetisstFolder(the plugin picks the file names), otherwise the file the user chose, with the result extension already appended if the user typed none.ReturnsTonCut 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;ParametersaWindowTHandleOwner window for any dialog the plugin shows. It is not always the main form: for example the input frame inLoadFileand the modal Save results dialog in the result callbacks.ReturnsTonCut 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;ParametersaWindowTHandleOwner window for any dialog the plugin shows. It is not always the main form: for example the input frame inLoadFileand the modal Save results dialog in the result callbacks.ReturnsTonCut 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
feSavePlotToFileis advertised andfeSaveResultToFileis not. A result other thancprOKis silent.Declaration
function SavePlot(aWindow: THandle; const aFileName: WideString; const aSolutionSheet: ISolutionSheet): TTcpResult; safecall;ParametersaWindowTHandleOwner window for any dialog the plugin shows. It is not always the main form: for example the input frame inLoadFileand the modal Save results dialog in the result callbacks.aFileNameconstWideStringPath of the file to inspect, load, or save.ReturnsTonCut 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
cprOKis silent.Declaration
function BatchSavePlot(aWindow: THandle; aSaveTarget: TTcpSaveTarget; const aPath: WideString; const aSolution: ISolution): TTcpResult; safecall;ParametersaWindowTHandleOwner window for any dialog the plugin shows. It is not always the main form: for example the input frame inLoadFileand the modal Save results dialog in the result callbacks.aSaveTargetBatch save target mode selected by the host.aPathconstWideStringThe folder the user chose whenaSaveTargetisstFolder(the plugin picks the file names), otherwise the file the user chose, with the result extension already appended if the user typed none.ReturnsTonCut 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)
- 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;ParametersaTypeExtension category being enumerated.aExtensionconstWideStringText value for extension.aNameconstWideStringText value for name.