Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Sonstige Fragen zu Delphi (https://www.delphipraxis.net/19-sonstige-fragen-zu-delphi/)
-   -   Delphi VBS (For Each xxx in xxxx) -> Delphi (https://www.delphipraxis.net/81323-vbs-each-xxx-xxxx-delphi.html)

Piro 24. Nov 2006 22:07


VBS (For Each xxx in xxxx) -> Delphi
 
Hi Leute,

ich hoffe einer kann mir den Code von VBS in Delphi übersetzen. Habe schon etwas übersetzt. Ich komme bloss mit der For Each xxx in xxxx nicht weiter. Was muss ich da nehmen.

Code:
' Original VBS Code

sActionName="Hardware Inventory Collection Cycle"

Dim oCPAppletMgr
Set oCPAppletMgr = CreateObject("CPApplet.CPAppletMgr")

Dim oClientActions
Set oClientActions = oCPAppletMgr.GetClientActions()

Dim oClientAction
For Each oClientAction In oClientActions
     If oClientAction.Name = sActionName Then
        oClientAction.PerformAction
     End If
Next
Mein Delphi Code
Delphi-Quellcode:
procedure vbscript;
var
  sActionName : string;
  oCPAppletMgr, oClientActions, oClientAction : Variant;
begin
 sActionName := 'Hardware Inventory Collection Cycle';

 oCPAppletMgr := CreateOleObject('CPApplet.CPAppletMgr');
 oClientActions := oCPAppletMgr.GetClientActions();

 for oClientAction in oClientActions do
 begin
   If oClientAction.Name = sActionName Then
        oClientAction.PerformAction;
 end;
end;
Denn letzten Teil mit der For-Schleife bekomme ich leider nicht hin. Wäre voll gut wenn mir einer helfen könnte.

Gruß, Sven

Bernhard Geyer 24. Nov 2006 22:24

Re: VBS (For Each xxx in xxxx) -> Delphi
 
Blinder versuch:

Delphi-Quellcode:
for i := 0 to oClientActions.length - 1 do
begin
  oClientAction := oClientActions.Items[i];
  ...

end;

Piro 24. Nov 2006 22:56

Re: VBS (For Each xxx in xxxx) -> Delphi
 
Danke für deine schnelle Antwort.

Aber ich bräuchte etwas sicheres. Kann schlecht Testen.

Danke, Sven

Bernhard Geyer 24. Nov 2006 23:07

Re: VBS (For Each xxx in xxxx) -> Delphi
 
Zitat:

Zitat von daywalker299
Aber ich bräuchte etwas sicheres. Kann schlecht Testen.

Kann auch schlecht testen. Habe diesen COM-Control nicht auf meinem Rechner.

Piro 24. Nov 2006 23:32

Re: VBS (For Each xxx in xxxx) -> Delphi
 
Habe gerade mal getestet.

Kommt mit einem Fehler:
Zitat:

"Exception der Klasse EOleSysError mit der Meldung "Invalid number of parameters"

Jennes 25. Nov 2006 10:24

Re: VBS (For Each xxx in xxxx) -> Delphi
 
wenn Du die Struktur des Objekts nicht hast wird's schwierig, evtl. gibt's ja auch ein oClientActions.Count oder oClientActions.Items.Count
Versuch macht kluch in diesem Fall

Piro 25. Nov 2006 10:59

Re: VBS (For Each xxx in xxxx) -> Delphi
 
Ich weiß nicht, wie die Struktur ist aber ich weiß was rauskommen muss.

Folgendes liefert das VBS Script, wenn man ein "MsgBox oClientAction.Name" einbaut.
Zitat:

Software Inventory Collection Cycle
MSI Product Source Update Cycle
Hardware Inventory Collection Cycle
Standard File Collection Cycle
Discovery Data Collection Cycle
Request & Evaluate User Policy
Request & Evaluate Machine Policy
Software Metering Usage Report Cycle
oClientActions.Count / oClientActions.Items.Count / oClientActions.length funktioniert leider nicht.

Ich hoffe mir kann noch einer sagen, wie ich das hinbekomme.

Piro 25. Nov 2006 11:30

Re: VBS (For Each xxx in xxxx) -> Delphi
 
Ich bin jetzt einen kleinen Schritt weiter. Es lag nicht unbedingt an der For-Schleife. Davor war auch schon ein Fehler.

Delphi-Quellcode:
procedure vbscript;
var
  sActionName : string;
  oCPAppletMgr, oClientActions, oClientAction : Variant;
  i: Integer;
begin
 sActionName := 'Hardware Inventory Collection Cycle';
 oCPAppletMgr := CreateOleObject('CPApplet.CPAppletMgr');
 oClientActions := oCPAppletMgr.GetClientActions;

 ShowMessage(IntToStr(oClientActions.Count)); //Liefert 8

 for i:=0 to oClientActions.Count do
   If oClientAction = sActionName Then  // Hier ist noch ein Fehler : oCLientAction ist leer
        oClientAction.PerformAction;
end;
Wie kann ich jetzt oClientAction die Elemente von oClientActions zuordnen? Array?

thkerkmann 25. Nov 2006 12:53

Re: VBS (For Each xxx in xxxx) -> Delphi
 
Hat Bernhard doch schon geschrieben
Delphi-Quellcode:
for ....
begin
  oClientAction := oClientActions.Items[i];
  ...
Gruss

Piro 25. Nov 2006 19:10

Re: VBS (For Each xxx in xxxx) -> Delphi
 
Danke an alle, irgendwie war ich blind.

Hier der endgültige Code:
Delphi-Quellcode:
procedure vbscript;
var
  oCPAppletMgr, oClientActions, oClientAction : OleVariant;
  i : Integer;
  sActionName : String;
begin
 sActionName := 'Hardware Inventory Collection Cycle';
 oCPAppletMgr := CreateOleObject('CPApplet.CPAppletMgr');
 oClientActions := oCPAppletMgr.GetClientActions;

 for i:=1 to oClientActions.Count do
 begin
   oClientAction := oClientActions.Item[i];
   //ShowMessage(oClientAction.Name);
   If oClientAction.Name = sActionName Then
        oClientAction.PerformAction;
 end;
end;
Schönen Samstag-Abend noch.


Alle Zeitangaben in WEZ +1. Es ist jetzt 10:24 Uhr.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz