Thema: Plugin-System

Einzelnen Beitrag anzeigen

Benutzerbild von paule32.jk
paule32.jk

Registriert seit: 24. Sep 2022
Ort: Planet Erde
356 Beiträge
 
Delphi 11 Alexandria
 
#3

AW: Plugin-System

  Alt 26. Aug 2023, 18:44
Hallo @mmw,
Danke für Deine Tipps !

Ich habe dann mal ein wenig weiter gebastelt...
- die Datei: plugin.pas:
Delphi-Quellcode:
unit plugin;

interface

uses
  Windows, Classes, SysUtils, Forms, Dialogs;

type
  TkPlugin = class(TObject)
  private
    FHostApplication: TApplication;
    FFileVersion : String;
    FFileName : String;
    FFileAuthor : String;
    FFileDescription: String;
    FManager : TComponent;
  public
    constructor Create;
    destructor Destroy; override;

    function GetNumCommands: Integer; virtual; stdcall;

    function GetVersion: String; virtual; stdcall;
    function GetName: String; virtual; stdcall;
    function GetAuthor: String; virtual; stdcall;
    function GetDescription: String; virtual; stdcall;

    procedure SetVersion(AString: String);

    property HostApplication: TApplication read FHostApplication;
    property FileName: String read FFileName;
    property Version: String read FFileVersion;
    property Manager: TComponent read FManager;
  end;

implementation

constructor TkPlugin.Create;
begin
end;

destructor TkPlugin.Destroy;
begin
end;

function TkPlugin.GetVersion: String;
begin
  result := FFileVersion;
end;

function TkPlugin.GetName: String;
var
  TheFileName : array[0..MAX_PATH] of char;
begin
  FillChar(TheFileName, sizeof(TheFileName), #0);
  GetModuleFileName(hInstance, TheFileName, sizeof(TheFileName));
  result := TheFileName;
end;

function TkPlugin.GetAuthor: String;
begin
  result := FFileAuthor;
end;

function TkPlugin.GetDescription: String;
begin
  result := FFileDescription;
end;

function TkPlugin.GetNumCommands: Integer;
begin
  result := 0;
end;

procedure TkPlugin.SetVersion(AString: String);
begin
  FFileVersion := AString;
end;

end.
- die Datei: pluginManager.pas
Delphi-Quellcode:
unit pluginManager;

interface

uses
  Windows, Classes, SysUtils, Forms, Dialogs,
  plugin;

type
  TkPlugInManager = class(TComponent)
  private
    FPlugins: TStrings;
    function GetPlugin(index: Integer): TkPlugin;
    function GetPluginCount: Integer;
    function GetVersion: String;
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;

    function LoadPlugin(FileName: String): Boolean; virtual;

    function UnLoadPlugin(FileName: String): Boolean; overload; virtual;
    function UnLoadPlugin(index: Integer): Boolean; overload; virtual;

    property Items[index: Integer] : TkPlugin read GetPlugin; default;
    property Count: Integer read GetPluginCount;

  published
    property Version: String read GetVersion;
  end;

implementation

constructor TkPlugInManager.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
end;

destructor TkPlugInManager.Destroy;
begin
  inherited Destroy;
end;

function TkPlugInManager.GetPlugin(index: Integer): TkPlugin;
begin
  result := Items[index];
end;

function TkPlugInManager.GetPluginCount: Integer;
begin
  result := FPlugins.Count;
end;

function TkPluginManager.GetVersion: String;
begin
end;

function TkPluginManager.LoadPlugin(FileName: String): Boolean;
begin
  result := true;
end;

function TkPlugInManager.UnLoadPlugin(FileName: String): Boolean;
begin
  result := true;
end;

function TkPluginManager.UnLoadPlugin(index: Integer): Boolean;
begin
  result := true;
end;

end.
ich teste gerade, ob man den Code als BPL oder als DLL auslagern kann/muss ...
Frag doch einfach
Alles was nicht programmiert werden kann, wird gelötet
  Mit Zitat antworten Zitat