Club Delphi  
    Paypal   FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Principal > Varios
Registrarse FAQ Miembros Calendario Guía de estilo Temas de Hoy

Coloboración Paypal con ClubDelphi

 
 
Herramientas Buscar en Tema Desplegado
  #5  
Antiguo 16-09-2020
elrayo76 elrayo76 is offline
Miembro
 
Registrado: ene 2004
Ubicación: En la tierra, por eso mis archivos en la tierra y no en la nuebe...
Posts: 305
Poder: 23
elrayo76 Va camino a la fama
Paso el código del método que tengo en mi clase genérico que tengo en mi clase para ejecutar cualquier método de los de WMI.


Código Delphi [-]
var
  objWMIObject:  ISWbemObject;
  objWMIMethod: SWbemMethod;
  objWMIProperty: SWbemProperty;
  objWMIProp: ISWbemProperty;
  objWMInstance: ISWbemObject;
  objWMInParams: ISWbemObject;
  objWMIOutParams: ISWbemObject;
  olePropValue: OleVariant;
  i: Integer;
  strParamName: String;

begin
  // Verifica si el componente está activo. Sale del método si se cuemple la condición.
  objGuard.CheckFalse(aWMIComponent.Active, ERR_CARBON_COMPONENT_ACTIVATED);

  // Instancia de la clase.
  objWMIObject := TWMIUtils.GetClassInstance(aWMIComponent.WMIServices, aInstanceProp, aInstanceValue, aWMIComponent.WMIClass);

  // No se encontró.
  if not Assigned(objWMIObject) then
  begin
    // Preparar el método.
    objWMIMethod := objWMIObject.Methods_.Item(AMethodName, 0);  // Acá es donde recibe el método que tiene que ejecutar.
    objWMInParams := objWMIMethod.InParameters;
    objWMIOutParams := objWMIMethod.OutParameters;

    // ¿Es un parámetro de entrada?.
    if Assigned(objWMInParams) then
    begin
      objWMInParams.Properties_.Get_Count;
      objWMInstance := objWMInParams.SpawnInstance_(0);
      objWMInParams.Properties_.Get_Count;

      // Recorre el array con los nombres de los parámetros.
      for i := 0 to Length(aParamNameArray) - 1 do
      begin
        // Valida el tipo del parámetro entrada/salida.
        if aParamTypeArray[i] = ptIn then
        begin
          // Acá carga los nombres y tipo de datos de los parámetros...

          objWMIProperty := objWMInstance.Properties_.Add(aParamNameArray[i], aParamDataTypeArray[i], False, 0);



          // En este lugar carga los valores de los parámetros...
          // ¿Que pasa si alguno de los parametros a cargar el del tipo ARRAY y no un simple valor?.

          if aParamDataTypeArray[i] = wbemCimtypeObject then
            olePropValue := null
          else
            olePropValue := aParamValueArray[i];

          objWMIProperty.Set_Value(olePropValue);
        end;
      end;
    end;

    objWMIOutParams := objWMIObject.ExecMethod_(AMethodName, objWMInstance, 0, nil);
    strParamName := aParamNameArray[Length(aParamNameArray) - 1];

    objWMIProp := objWMIOutParams.Properties_.Item('ReturnValue', 0);
    VarClear(olePropValue);
    aResult := objWMIProp.Get_Value;

    // Recupera los parámetros de salida.
    if Assigned(objWMIOutParams) then
    begin
      objWMIOutParams.Properties_.Get_Count;
      objWMInstance := objWMIOutParams.SpawnInstance_(0);

      // Recorre el array con los nombres de los parámetros.
      for i := 0 to Length(aParamNameArray) - 1 do
      begin
        // Si es un parámetro de salida.
        if aParamTypeArray[i] = ptOut then
        begin
          objWMIProp := objWMIOutParams.Properties_.Item(aParamNameArray[i], 0);
          VarClear(olePropValue);
          olePropValue := objWMIProp.Get_Value;
          aParamValueArray[i] := olePropValue;
        end;
      end;
    end;
  end;


Más alla de que a este método los parámetro que le llegan son un array, que eso lo manejo bien. Uno de los items de ese array es otro array y es el que no se como se manda a WMI cada uno de esos items.


Espero que se entienda. Cualquier cosa me preguntas.


Saludos
__________________
Si tienes una función o procedimiento con diez parámetros, probablemente hayas olvidado uno
Responder Con Cita
 



Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro

Temas Similares
Tema Autor Foro Respuestas Último mensaje
Como se pasan los valores en un array de tipo string en c# uper .NET 1 13-06-2013 17:35:00
Un array loco por paso de parámetros de referencia ManiacPC OOP 2 14-10-2011 01:00:28
Longitud maxima de un array tipo string!! cristian_abb Varios 5 25-07-2006 23:53:39
devolver array de tipo tdate maruenda Varios 5 03-12-2004 19:34:56
Como Asignar Variable Tipo Array de Tform a otro Array del Mismo tipo morfeo21 Varios 5 17-08-2004 17:39:51


La franja horaria es GMT +2. Ahora son las 11:33:30.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi
Copyright 1996-2007 Club Delphi