Einzelnen Beitrag anzeigen

msickel

Registriert seit: 14. Mai 2005
108 Beiträge
 
Delphi 2005 Professional
 
#9

AW: Speicher Freigabe?

  Alt 17. Aug 2010, 20:03
Hi, leider komme ich nicht wirklich weiter, ich habe folgenden Code der aber bei jedem Druck auf den Button Speicher frisst, was mache ich falsch?

Bin für jede Hilfe dankbar

Delphi-Quellcode:

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ComCtrls, activex, comobj, ExtCtrls,
  ShellAPI, ExceptionLog;

type
  TForm1 = class(TForm)
    ListBox1: TListBox;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
    
  private
    { Private declarations }
  public
    { Public declarations }
    
  end;

var
  Form1: TForm1;

implementation


{$R *.dfm}


uses
  WbemScripting_TLB;


var
  aLoc : ISWbemLocator;
  aSrv : ISWbemServices;
  aObjSet : ISWbemObjectSet;
  pEnum : IEnumVARIANT;
  vOut : OleVariant;
  dwRetrieved : LongWord;
  hRes : HResult;
  sNetConnectionID, sNetConnectionStatus : String;
  iNetConnectionStatus : Integer;

function GetLocator : ISWbemLocator;
begin
  if not Assigned(aLoc) then
     aLoc := CoSWbemLocator.Create;

  result := aLoc;
end;

function GetServices : ISWbemServices;
begin
  if not Assigned(aSrv) then
     aSrv := aLoc.ConnectServer ('','root\cimv2', '','','','',0, nil);

  result := aSrv;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin

  Listbox1.Items.Clear;

  aLoc := GetLocator;
  aSrv := GetServices;

  aObjSet := aSrv.ExecQuery ('SELECT NetConnectionID, NetConnectionStatus FROM Win32_NetworkAdapter', 'WQL', 0, nil);

  pEnum := aObjSet.Get__NewEnum as IEnumVARIANT;

  while (true) do
  begin
    hRes := pEnum.Next (1, vOut, dwRetrieved);
    if not (hRes = S_OK) then
      Break;

    if (VarIsNull(vOut.NetConnectionID)) then
      Continue;

    sNetConnectionID := vOut.NetConnectionID;
    iNetConnectionStatus := vOut.NetConnectionStatus;
    if iNetConnectionStatus = 2 then
      sNetConnectionStatus := 'verbunden';
    if iNetConnectionStatus = 7 then
      sNetConnectionStatus := 'nicht verbunden';

    ListBox1.Items.Add(sNetConnectionID + ' = ' + sNetConnectionStatus);

  end;

// VarClear(vOut);
// hRes := 0;
// pEnum := nil;
// aLoc := nil;
// aSrv := nil;
// aObjSet := nil;

end;

end.
Martin
ich weiss, das ich nichts weiss!
  Mit Zitat antworten Zitat