Einzelnen Beitrag anzeigen

nahpets
(Gast)

n/a Beiträge
 
#8

Re: COM - For-Each in Delphi, aber wie?

  Alt 1. Aug 2008, 10:37
Hallo,

ich ahne, was Dein Problem ist, weiß aber keine Lösung.

Eventuell hilft Dir der Auszug aus einem Quelltext von einem meiner Programme:
Delphi-Quellcode:
      wmiObjectSet := wmiServices.InstancesOf(sClass, wbemFlagReturnImmediately or wbemQueryFlagShallow, nil);
      Enum := (wmiObjectSet._NewEnum) as IEnumVariant;
      bOk := False;
      while (Enum.Next(1, ovVar, lwValue) = S_OK) do begin
        bOk := True;
        wmiObject := IUnknown(ovVar) as SWBemObject;
        propSet := wmiObject.Properties_;
        propEnum := (propSet._NewEnum) as IEnumVariant;

        while (propEnum.Next(1, ovVar, lwValue) = S_OK) do begin
          wmiProp := IUnknown(ovVar) as SWBemProperty;
          sValue := '';
          if VarIsNull(wmiProp.Get_Value) then sValue := 'Is Nullelse
          case wmiProp.CIMType of
            wbemCimtypeSint8,
            wbemCimtypeUint8,
            wbemCimtypeSint16,
            wbemCimtypeUint16,
            wbemCimtypeSint32,
            wbemCimtypeUint32,
            wbemCimtypeSint64:
              if VarIsArray(wmiProp.Get_Value) then begin
                if VarArrayHighBound(wmiProp.Get_Value, 1) > 0 then begin
                  for Count := 1 to VarArrayHighBound(wmiProp.Get_Value, 1) do begin
                    sValue := sValue + ' ' + IntToStr(wmiProp.Get_Value[Count]);
                  end;
                end;
              end else sValue := IntToStr(wmiProp.Get_Value);

            wbemCimtypeReal32,
            wbemCimtypeReal64: sValue := FloatToStr(wmiProp.Get_Value);

            wbemCimtypeBoolean: if wmiProp.Get_Value then sValue := 'Trueelse sValue := 'False';

            wbemCimtypeString,
            wbemCimtypeUint64:
              if VarIsArray(wmiProp.Get_Value) then begin
                if VarArrayHighBound(wmiProp.Get_Value, 1) > 0 then begin
                  for Count := 1 to VarArrayHighBound(wmiProp.Get_Value, 1) do begin
                    sValue := sValue + ' ' + wmiProp.Get_Value[Count];
                  end;
                end;
              end else begin
                sValue := wmiProp.Get_Value;
              end;
            wbemCimtypeDatetime:
              sValue := wmiProp.Get_Value;
          else
            begin
              Try
                sValue := wmiProp.Get_Value;
              Except
                on e : Exception Do Begin
                  sValue := 'Wert kann nicht gelesen werden: ' + e.Message;
                end;
              End;
            end;
          end;
          sl.Add(wmiProp.Name + '=' + sValue);
        End;
Mit diesem Teil habe ich jedoch ein Problem, da ist irgendwo ein Speicherloch drin, dass ich nicht finde.
Läuft das Programm lange genug, ist irgendwann der Speicher voll.

Stephan
  Mit Zitat antworten Zitat