AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

TList und Interfaces Problem

Ein Thema von Neutral General · begonnen am 3. Mär 2007 · letzter Beitrag vom 3. Mär 2007
Antwort Antwort
Benutzerbild von Neutral General
Neutral General

Registriert seit: 16. Jan 2004
Ort: Bendorf
5.219 Beiträge
 
Delphi 10.2 Tokyo Professional
 
#1

TList und Interfaces Problem

  Alt 3. Mär 2007, 17:34
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
Michael
"Programmers talk about software development on weekends, vacations, and over meals not because they lack imagination,
but because their imagination reveals worlds that others cannot see."
  Mit Zitat antworten Zitat
Hawkeye219

Registriert seit: 18. Feb 2006
Ort: Stolberg
2.227 Beiträge
 
Delphi 2010 Professional
 
#2

Re: TList und Interfaces Problem

  Alt 3. Mär 2007, 17:42
Hallo Michael,

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

Gruß Hawkeye
  Mit Zitat antworten Zitat
Benutzerbild von Neutral General
Neutral General

Registriert seit: 16. Jan 2004
Ort: Bendorf
5.219 Beiträge
 
Delphi 10.2 Tokyo Professional
 
#3

Re: TList und Interfaces Problem

  Alt 3. Mär 2007, 17:44
Ja das kann schon sein.. Nur wie mach ich das ?
Michael
"Programmers talk about software development on weekends, vacations, and over meals not because they lack imagination,
but because their imagination reveals worlds that others cannot see."
  Mit Zitat antworten Zitat
Hawkeye219

Registriert seit: 18. Feb 2006
Ort: Stolberg
2.227 Beiträge
 
Delphi 2010 Professional
 
#4

Re: TList und Interfaces Problem

  Alt 3. Mär 2007, 17:48
New (Result); wäre die einfachste Lösung.

Gruß Hawkeye
  Mit Zitat antworten Zitat
Benutzerbild von Neutral General
Neutral General

Registriert seit: 16. Jan 2004
Ort: Bendorf
5.219 Beiträge
 
Delphi 10.2 Tokyo Professional
 
#5

Re: TList und Interfaces Problem

  Alt 3. Mär 2007, 17:52
Ok danke es klappt jetzt

Gruß
Neutral General
Michael
"Programmers talk about software development on weekends, vacations, and over meals not because they lack imagination,
but because their imagination reveals worlds that others cannot see."
  Mit Zitat antworten Zitat
Antwort Antwort


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 02:57 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