Einzelnen Beitrag anzeigen

Blup

Registriert seit: 7. Aug 2008
Ort: Brandenburg
1.429 Beiträge
 
Delphi 10.4 Sydney
 
#12

AW: Supports ohne out Parameter

  Alt 10. Okt 2012, 12:12
Zur Verdeutlichung des Ablaufs:
Delphi-Quellcode:
var
  a: TFirstSecond;
  i: IInterface;
  f: IFirst;
  s: ISecond;

begin
  a := TFirstSecond.Create;
  i := a; // a.RefCount wird 1

  if Supports(a, IFirst) then // a.RefCount wird 2 und wieder 1
    Writeln('a supports IFirst');

  if Supports(a, ISecond) then // a.RefCount wird 2 und wieder 1
    Writeln('a supports ISecond');

  if Supports(a, IFirst, f) then // a.RefCount wird 2
    Writeln('[out] a supports IFirst');

  if Supports(a, ISecond, s) then // a.RefCount wird 3
    Writeln('[out] a supports ISecond');
  
  i := nil; // a.RefCount wird 2
  f := nil; // a.RefCount wird 1
  s := nil; // a.RefCount wird 0 und a wird freigegeben

  Readln;
end.
  Mit Zitat antworten Zitat