Einzelnen Beitrag anzeigen

user0

Registriert seit: 28. Okt 2005
25 Beiträge
 
Delphi 7 Personal
 
#1

Komponente in DLL auzslagern

  Alt 11. Jun 2007, 13:03
Hallo leute,

ich arbeite an einem größeren Softwareprojekt. Ein Formular enthält eine Komponente (TGLMaterialLibrary vom GLScene-Package), dass nicht von der Language-Suite compiliert werden kann. Ich versuche nun diese Komponente auf ein Formular in einer DLL zu kopieren, und diese zur Laufzeit des Programms aus der DLL zu laden.

Hier der Code der DLL:

Hauptprogramm:
Delphi-Quellcode:
library MatLibDll;

{ Important note about DLL memory management: ShareMem must be the
  first unit in your library's USES clause AND your project's (select
  Project-View Source) USES clause if your DLL exports any procedures or
  functions that pass strings as parameters or function results. This
  applies to all strings passed to and from your DLL--even those that
  are nested in records and classes. ShareMem is the interface unit to
  the BORLNDMM.DLL shared memory manager, which must be deployed along
  with your DLL. To avoid using BORLNDMM.DLL, pass string information
  using PChar or ShortString parameters. }


uses
  ShareMem,
  SysUtils,
  Classes,
  formular in 'formular.pas{Form1};

exports
   get_matLib;

{$R *.RES}

var exitProc_save: pointer;

procedure MyExit();
begin
   if Assigned(Form1) then begin
      Form1.Close;
      Form1.Free;
   end;
   ExitProc := exitProc_save;
end;

begin
   exitProc_save := @ExitProc;
   ExitProc := @MyExit;
   Form1 := TForm1.Create(nil);
   Form1.Show;
end.
Formular:
Delphi-Quellcode:
unit formular;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  GLMisc, GLTexture;

type PGLMaterialLibrary = ^TGLMaterialLibrary;

type
  TForm1 = class(TForm)
    MaterialLib: TGLMaterialLibrary;
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var   Form1: TForm1;

function get_matLib(): TGLMaterialLibrary; stdcall;

implementation

{$R *.DFM}

function get_matLib(): TGLMaterialLibrary;
begin
   if not Assigned(Form1)   then Form1 := TForm1.Create(nil);
   result := Form1.MaterialLib;
end;

end.
Im eigentlichen Programm wird die DLL Statisch geladen. Die "fehlerhafte" Komponente habe ich im Designer gelöscht, und die Eigenschaft im Code wider hinzugefügt. Bei FormCreate wird dann folgendes gemacht:

self.MaterialLib := get_matLib(); Eigentlich sollte doch jetzt das weitere Programm gar nicht merken, dass die Komponente nicht auf dem Formblatt liegt?
Trotzdem kommt bei einer Zuweisung ("FF.Material := MaterialLib.Materials.GetLibMaterialByName('MarkedCase').Material; ") eine Fehlermeldung: "Can not assign TGLMaterialLibrary to a TGLMaterialLibrary". Die Assign-methode ist aber im GLScene Package für solche Objekte definiert.

Wo liegt der Fehler? Oder gibt es eine bessere Möglichkeit eine Komponente von einem Formular in eine extra DLL oder Ressource auszulagern?

user0
  Mit Zitat antworten Zitat