Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Sonstige Fragen zu Delphi (https://www.delphipraxis.net/19-sonstige-fragen-zu-delphi/)
-   -   Delphi TList und Interfaces Problem (https://www.delphipraxis.net/87649-tlist-und-interfaces-problem.html)

Neutral General 3. Mär 2007 17:34


TList und Interfaces Problem
 
Hi,

Ich glaube es hat nur indirekt was mit Interfaces zu tun. Jedenfalls probiere ich mich grad ein bisschen an Dll-Interface-Plugins.

Wichtige Klassen etc:
Delphi-Quellcode:
_Plugin = record
    hLib: THandle;
    Plugin: IPlugin;
  end;

_PPlugin = ^_Plugin;

//..

  TPluginList = class(TList)
  private
    function GetItem(Index: Integer): _PPlugin;
    procedure SetItem(Index: Integer; const Value: _PPlugin);
  public
    function Add(Item: _PPlugin): Integer;
    property Items[Index: Integer]: _PPlugin read GetItem write SetItem;
  end;

function TPluginList.Add(Item: _PPlugin): Integer;
begin
  Result := inherited Add(Item);
end;

function TPluginList.GetItem(Index: Integer): _PPlugin;
begin
  Result := _PPlugin(inherited Items[Index]);
end;

procedure TPluginList.SetItem(Index: Integer; const Value: _PPlugin);
begin
  inherited Items[Index] := Value;
end;

function TForm1.LoadPlugin(DllName: PChar): _PPlugin;
var hLib: THandle;
    x: TInitPlugin;
begin
  hLib := LoadLibrary(DllName);
  if hLib <> 0 then
  begin
   @x := GetProcAddress(hLib,'InitPlugin');
   
   Result^.hLib := hLib;
   Result^.Plugin := x;
  end;
end;

Delphi-Quellcode:
var pTmp: _PPLugin;
begin
  pTmp := LoadPlugin('Plugin.dll');
  PlugInList.Add(pTmp);
  //...
end;
Wenn ich mein Programm beende bekomme ich eine AV und einen Runtime Error... Woher kommt das?

Gruß
Neutral General

Hawkeye219 3. Mär 2007 17:42

Re: TList und Interfaces Problem
 
Hallo Michael,

du forderst in der Methode TForm1.LoadPlugin keinen Speicher für das Funktionsergebnis an.

Gruß Hawkeye

Neutral General 3. Mär 2007 17:44

Re: TList und Interfaces Problem
 
Ja das kann schon sein.. Nur wie mach ich das ? :|

Hawkeye219 3. Mär 2007 17:48

Re: TList und Interfaces Problem
 
Delphi-Quellcode:
New (Result);
wäre die einfachste Lösung.

Gruß Hawkeye

Neutral General 3. Mär 2007 17:52

Re: TList und Interfaces Problem
 
Ok danke es klappt jetzt :)

Gruß
Neutral General


Alle Zeitangaben in WEZ +1. Es ist jetzt 08:38 Uhr.

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