Hi,
Sorry wegen dem Titel. Mir ist nach 5 Minuten immernoch kein besserer eingefallen. Falls jemand einen besseren Namen weiß, werd ichs ändern.
Zu meiner Frage:
Ich schreibe ein Programm und das kann sagen wir mal .abc Dateien öffnen (also gemeint ist nicht das .abc Format sonder ein x-beliebiges). Dann soll es möglich sein per
DLL dem Programm die Fähigkeit zu geben auch .xyz Dateien öffnen zu können.
Also meine Anwendung ist eine
MDI-Anwendung. Das Pluginsystem funktioniert im Moment so:
Anwendung:
Delphi-Quellcode:
procedure TForm1.FormCreate(Sender: TObject);
var dll: hModule;
Register:
procedure(
const List: TFileFormatList);
begin
List := TFileFormatList.Create;
dll := LoadLibrary('
DLL\Formats.dll');
Register := GetProcAddress(
dll,'
Register');
Register(List);
end;
procedure TForm1.Button1Click(Sender: TObject);
var AFile: IFileFormat;
begin
if Opendialog1.Execute
then
begin
AFile := List.GetFormat(ExtractFileExt(Opendialog1.Filename));
AFile.LoadFromFile(Opendialog1.Filename);
end;
end;
DLL
Delphi-Quellcode:
library Plugin;
uses
Classes,
FFTypes;
{$R *.res}
type
T3D2File = class(TInterfacedObject, IFileformat)
public
procedure LoadFromFile(const Filename: PChar);
end;
{ T3D2File }
procedure T3D2File.LoadFromFile(const Filename: PChar);
begin
ShowMessage('3d2.LoadFromFile: ' + Filename);
end;
function New3D2: IFileFormat;
begin
Result := T3d2File.Create;
end;
procedure Register(const List: TFileFormatList);
begin
List.Add('.3d2',@New3D2);
end;
exports
Register;
begin
end.
Schnittstelle:
Delphi-Quellcode:
unit FFTypes;
interface
uses Classes;
type
IFileFormat =
Interface(IUnknown)
['
{1CF74E69-391A-4BF4-8F0D-E5C958D21196}']
procedure LoadFromFile(
const Filename: PChar);
end;
TCreateFile =
function: IFileFormat;
PFileFormat = ^TFileFormat;
TFileformat =
record
Ext:
String;
Proc: TCreateFile;
end;
TFileFormatList =
class(TList)
private
function GetItems(
Index: Integer): PFileFormat;
procedure SetItems(
Index: Integer;
const Value: PFileFormat);
public
function Add(
const AExt:
String; AProc: TCreateFile): Integer;
function GetFormat(
const AExt:
String): IFileFormat;
property Items[
Index: Integer]: PFileFormat
read GetItems
write SetItems;
default;
end;
implementation
{ TFileFormatList }
function TFileFormatList.Add(
const AExt:
String; AProc: TCreateFile): Integer;
var newFile: PFileFormat;
begin
New(NewFile);
with NewFile^
do
begin
Ext := AExt;
Proc := AProc;
end;
Result :=
inherited Add(NewFile);
end;
function TFileFormatList.GetFormat(
const AExt:
String): IFileFormat;
var i: Integer;
begin
for i:= 0
to Count-1
do
if Items[i].Ext = AExt
then
begin
Result := Items[i].Proc();
exit;
end;
Result :=
nil;
end;
Das funktioniert soweit auch aber das eigentliche Problem ist, dasses sein kann, das .abc eine Bilddatei ist und .xyz eine Audiodatei und .asd eine Textdatei etc. Und je nachdem sieht das Fenster, in dem die Datei dargestellt wird anders aus. Also man kann ja z.B. kein Bitmap auf einem Formular darstellen, welches dafür gedacht ist Audiodateien abzuspielen usw. Jetzt ist die Frage wie man sowas lösen kann. Ich könnte es theoretisch anstellen, dass das Plugin das Formular für seine Datei komplett alleine erstellen kann/darf. Aber da hat das Plugin einfach zu viel Macht. Man kann ja auf son Formular sonstwas programmieren. Versteht ihr das Problem?
Jetzt ist die Frage wie ich sowas realisieren kann.
Wenn ihr jetzt nichts verstanden habt dann fragt nochmal nach
Gruß
Neutral General