![]() |
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:
Mein Delphi 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
Delphi-Quellcode:
Denn letzten Teil mit der For-Schleife bekomme ich leider nicht hin. Wäre voll gut wenn mir einer helfen könnte.
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; Gruß, Sven |
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; |
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 |
Re: VBS (For Each xxx in xxxx) -> Delphi
Zitat:
|
Re: VBS (For Each xxx in xxxx) -> Delphi
Habe gerade mal getestet.
Kommt mit einem Fehler: Zitat:
|
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 |
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:
Ich hoffe mir kann noch einer sagen, wie ich das hinbekomme. |
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:
Wie kann ich jetzt oClientAction die Elemente von oClientActions zuordnen? Array?
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; |
Re: VBS (For Each xxx in xxxx) -> Delphi
Hat Bernhard doch schon geschrieben
Delphi-Quellcode:
Gruss
for ....
begin oClientAction := oClientActions.Items[i]; ... |
Re: VBS (For Each xxx in xxxx) -> Delphi
Danke an alle, irgendwie war ich blind.
Hier der endgültige Code:
Delphi-Quellcode:
Schönen Samstag-Abend noch.
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; |
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