Delphi-PRAXiS
Seite 4 von 4   « Erste     234   

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Programmieren allgemein (https://www.delphipraxis.net/40-programmieren-allgemein/)
-   -   TCollection = not TCollection ? (https://www.delphipraxis.net/161506-tcollection-%3D-not-tcollection.html)

jaenicke 7. Jul 2011 18:29

AW: TCollection = not TCollection ?
 
Zitat:

Zitat von EWeiss (Beitrag 1110490)
Zitat:

Zitat von himitsu (Beitrag 1110480)
Dann nimm eben keine DLL, sondern eine BPL. [...]

Die muss man aber Installieren oder?

Nein, mit LoadPackage laden. ;-)
http://edn.embarcadero.com/article/27178

Was eine DLL angeht, so müsstest du als Parameter auch Interfaces, z.B. abgeleitet von IUnknown, übergeben können. Denn die werden via COM verwaltet. Also so ca., ungetestet:
Delphi-Quellcode:
library xyz;

uses
  MyInterface;

procedure DoIt(AObject: ITest); stdcall;
begin
  MessageBox(0, AObject.GetMsg, 'test', MB_ICONINFORMATION or MB_OK);
  AObject.ShowMsg('Hallo');
end;

exports
  DoIt;
Delphi-Quellcode:
unit MyInterface;

interface

type
  ITest = interface(IUnknown)
    procedure ShowMsg(Value: PWideChar); stdcall;
    function GetMsg: PWideChar; stdcall;
    procedure SetMsg(Value: PWideChar); stdcall;
  end;
Benutzung:
Delphi-Quellcode:
uses
  MyInterface;

type
  TTest = class(TInterfacedObject, ITest)
  private
    FTest: string;
  public
    procedure ShowMsg(Value: PWideChar); stdcall;
    function GetMsg: PWideChar; stdcall;
    procedure SetMsg(Value: PWideChar); stdcall;
  end;

procedure DoIt(AObject: ITest); stdcall; external 'xyz.dll';

implementation

function TTest.GetMsg: PWideChar;
begin
  Result := PWideChar(FTest);
end;

procedure TTest.SetMsg(Value: PWideChar);
begin
  FTest := Value;
end;

procedure TTest.ShowMsg(Value: PWideChar);
begin
  ShowMessage(Value);
end;
Delphi-Quellcode:
var
  Test: ITest;
begin
  Test := TTest.Create;
  Test.SetMsg('Hallöchen');
  DoIt(Test);
  Test := nil; // explizite Freigabe, nur nötig, wenn sonst der Scope zu groß wäre
Vielleicht hilft dir das ja dabei das so zu kapseln oder so. ;-)

// EDIT:
Also ich denke da an so etwas wie ein Interface, das du der DLL übergibst und das in der Anwendung die Daten abruft und in Interface-Objekten der DLL liefert ;-)

EWeiss 7. Jul 2011 18:34

AW: TCollection = not TCollection ?
 
Danke für eure Infos werde es mir mal anschauen.

gruss

himitsu 7. Jul 2011 18:47

AW: TCollection = not TCollection ?
 
Statt dem PWideChar kann man im Interface auch WideString nehmen, denn dieses wird auch über das COM-Zeugs verwaltet.


Alle Zeitangaben in WEZ +1. Es ist jetzt 14:46 Uhr.
Seite 4 von 4   « Erste     234   

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz