Announcement

Collapse
No announcement yet.

Assembly in Delphi 8 erstellen

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Assembly in Delphi 8 erstellen

    Hallo,

    ich habe in Delphi 8 ein paar Klassen geschrieben, die ich in ein Assembly packen möchte, damit ich sie z.B. auch mit C# nutzen kann.

    Was muss ich für diesen Zweck nehmen, eine Library oder ein Package ? Bei Libraries schaffe ich es nur mittels 'exports' Anweisung einzelne Methoden zu exportieren, nicht aber ganze Klassen.

    Kann mir jemand weiterhelfen ?

  • #2
    Hallo,

    rein technisch gesehen gibt es keinen Unterschied zwischen Library und Package. Der <i>Exports</i>-Block wird nur für den Sonderfall <i>Unmanaged Export</i> benötigt (d.h. ein Win32-Programm soll die .NET-Assembly als "ganz normale" DLL importieren und aufrufen dürfen).

    Eine Package ist eine normale .NET-Assembly, die jedoch im Gegensatz zu einer mit Delphi 8 compilierten Library bereits einen Link zum Namespace <i>Borland.Delphi.System</i> enthält, wobei die Delphi 8-RTL (Runtime Library) aus der externen Assembly <i>Borland.Delphi.dll</i> eingebunden wird. Im Fall eines Library-Projekts müssen wir selbst von Hand dem Projekt einen Verweis auf die Delphi 8-RTL hinzufügen.

    Das folgende Beispiel implementiert einen <i>.NET Enterprise Service</i> als Library-Projekt in eine Assembly-DLL:
    <pre>
    <b>library</b> Delphi8FixInterface;
    <br>
    <font color="#003399"><i>{%DelphiDotNetAssemblyCompiler 'c:\programme\gemeinsame dateien\borland shared\bds\shared assemblies\2.0\Borland.Delphi.dll'}</i></font>
    <font color="#003399"><i>{%DelphiDotNetAssemblyCompiler '$(SystemRoot)\microsoft.net\framework\v1.1.4322\S ystem.EnterpriseServices.dll'}</i></font>
    <br>
    <b>uses</b>
    System.Reflection,
    System.EnterpriseServices,
    System.Runtime.InteropServices;
    <br>
    [assembly: ApplicationName(<font color="#9933CC">'Delphi8ESFixInterfaceDemo'</font>)]
    [assembly: ApplicationActivation(ActivationOption.Server)]
    [assembly: ApplicationAccessControl(Value=True,
    Authentication=AuthenticationOption.Connect,
    ImpersonationLevel=ImpersonationLevelOption.Identi fy,
    AccessChecksLevel=AccessChecksLevelOption.Applicat ionComponent)]
    [assembly: DescriptionAttribute(<font color="#9933CC">'Delphi 8 Interface .NET Enterprise Services-Objekt'</font>)]
    [assembly: SecurityRole(<font color="#9933CC">'Benutzer'</font>, SetEveryoneAccess = True)]
    <br>
    <font color="#003399"><i>// STRG+UMSCHALT+G legt neue GUID für die Assembly fest</i></font>
    [assembly: Guid(<font color="#9933CC">'854A605E-3F7E-4625-A79B-DA6E074269BA'</font>)]
    <br>
    [assembly: AssemblyTitle(<font color="#9933CC">'Delphi8ESFix'</font>)]
    [assembly: AssemblyDescription(<font color="#9933CC">'Delphi 8 FixInterface .NET Enterprise Service'</font>)]
    [assembly: AssemblyVersion(<font color="#9933CC">'1.1.0.0'</font>)]
    [assembly: AssemblyDelaySign(False)]
    [assembly: AssemblyKeyFile(<font color="#9933CC">'ES.snk'</font>)]
    [assembly: AssemblyKeyName(<font color="#9933CC">''</font>)]
    <br>
    <b>type</b>
    IOSDelphi8ESObj = <b>interface</b>
    <b>function</b> DoWork(sInput: <b>String</b>): <b>String</b>;
    <b>end</b>;
    <br>
    [TransactionAttribute(TransactionOption.NotSupporte d),
    ConstructionEnabled(<b>Default</b>=<font color="#9933CC">'Delphi 8 FixInterface'</font>),
    JustInTimeActivation(True),
    EventTrackingEnabled(True),
    DescriptionAttribute(<font color="#9933CC">'Delphi 8 FixInterface .NET Enterprise Services-Objekt'</font>),
    Guid(<font color="#9933CC">'356C3A64-88B3-4AA6-B644-D89D103B2F41'</font>),
    ObjectPooling(MinPoolSize=2, MaxPoolSize=5),
    ClassInterface(ClassInterfaceType.None)]
    TOSDelphi8ESObj = <b>class</b>(ServicedComponent, IOSDelphi8ESObj)
    <b>private</b>
    FConstructString: <b>String</b>;
    <b>protected</b>
    <b>procedure</b> Construct(constructString: <b>String</b>); <b>override</b>;
    <b>public</b>
    <b>function</b> DoWork(sInput: <b>String</b>): <b>String</b>;
    <b>end</b>;
    <br>
    <font color="#003399"><i>{ TOSDelphi8ESObj }</i></font>
    <br>
    <b>procedure</b> TOSDelphi8ESObj.Construct(constructString: <b>String</b>);
    <b>begin</b>
    <b>inherited</b>;
    FConstructString := constructString;
    <b>end</b>;
    <br>
    <b>function</b> TOSDelphi8ESObj.DoWork(sInput: <b>String</b>): <b>String</b>;
    <b>begin</b>
    Result := sInput + <font color="#9933CC">': '</font> + FConstructString;
    ContextUtil.SetComplete;
    <b>end</b>;
    <br>
    <b>begin</b>
    <b>end</b>.
    </pre>
    Diese Assembly-DLL kann problemlos von anderen Delphi 8- und VS2003-Projekten eingebunden werden.

    Da die Delphi 8-IDE aber im rauhen Alltags-Einsatz einige Problem mit Library-Projekten hat, empfiehlt Borland generell, nur für den Unmanaged Export-Sonderfall zu einem Library-Projekt zu greifen und statt dessen generell eine Package zu verwenden. Es sei denn, die Assembly muss einen Strong Name verwenden (in diesem Fall geht zur Zeit auch nach dem Update#2 Package nicht, sondern nur Library).

    Comment


    • #3
      Danke für die Hilfe, ich werde gleich mal versuchen es umzusetzen

      Comment

      Working...
      X