Einzelnen Beitrag anzeigen

HeikoDD

Registriert seit: 8. Okt 2003
11 Beiträge
 
#5

Re: Problem Mit Interface-Objekt

  Alt 27. Apr 2007, 21:59
vielleicht hilft das etwas, also bei mir läuft es unter d5 ohne probleme.

Delphi-Quellcode:
const IIDHaupt : TGUID = '{EA6A5E02-3B7D-458E-898D-101F76832635}';

type iHaupt = interface(IUnknown)
       ['{EA6A5E02-3B7D-458E-898D-101F76832635}']
       procedure MyLoop; stdcall;
     end;

////////////////////////////////////////////////////////////////////////////////
type tCustomClass = class(tObject)
       protected
         fApplet : Array of IHaupt;
         procedure SetIhaupt(Index:Integer; Value:IHaupt); stdcall;
         function GetIHaupt(Index:integer):IHaupt; stdcall;
       public
         constructor Create;
         destructor Destroy; override;
         property Haupts[Index:Integer]:IHaupt read GetIHaupt write SetIHaupt;
     end;


procedure tCustomClass.SetIhaupt(Index:Integer; Value:IHaupt); stdcall;
begin
  if (Index > -1) and (Index < 6) then fapplet[Index] := Value else
    raise exception.CreateFmt('Bad Index %d',[Index]);
end;

function tCustomClass.GetIHaupt(Index:Integer):IHaupt; stdcall;
begin
  result := nil;
  if (index < 0) or (index > 6) then exit
    else result := fApplet[Index];
end;

constructor tCustomClass.create();
begin
  inherited;
  setlength(fApplet, 6);
end;

destructor tCustomClass.destroy;
var i:Integer;
begin
 for i := low(fApplet) to high(fApplet) do
   fApplet[i] := nil;
 inherited;
end;
////////////////////////////////////////////////////////////////////////////////

type tHauptClass = class(tInterfacedObject, IHaupt)
       protected
         procedure MyLoop; stdcall;
       public
     end;

procedure tHauptClass.MyLoop; stdcall;
begin
  showmessage('hui');
end;

////////////////////////////////////////////////////////////////////////////////

procedure TForm1.FormCreate(Sender: TObject);
var i, j : integer;
    IH : IHaupt;
begin
  j := 0;
  with tCustomClass.Create do begin
    for i := 1 to 1000 do begin
      for j := 0 to 5 do begin
        IH := NIL;
        IH := tHauptClass.Create;
        Haupts[j] := IH;
      end;

      for j := 5 downto 0 do begin
        IH := Haupts[j];
        if (ih <> nil) then ih.MyLoop;
        Haupts[j] := NIL;
      end;
    end;
  end;
end;
  Mit Zitat antworten Zitat