![]() |
powershell cmdlet (delphi.net)
I am trying to convert
![]() I installed PowerShell and made a reference to the System.Management.Automation.dll. On this code:
Delphi-Quellcode:
I get error [DCC Error] uMain.pas(41): E2003 Undeclared identifier: 'Create' on the line rc := RunSpaceConfiguration.Create;
uses
... system.IO, system.Collections.Generic, system.Management.Automation, system.Management.Automation.Host, system.Management.Automation.Runspaces; ... var rc: RunspaceConfiguration; snapEx: PSSnapInException; info: PSSnapInInfo; myRunSpace: Runspace; pl: PipeLine; newMbx: Command; begin snapEx := nil; rc := RunSpaceConfiguration.Create; info := rc.AddPSSnapIn('Microsoft.Exchange.Management.PowerShell.Admin', snapEx); MyRunSpace := RunspaceFactory.CreateRunspace(rc); MyRunSpace.Open; pl := MyRunSpace.CreatePipeline; According to MSDN the RunSpaceConfiguration class is abstract that might have something to do with it, but in all examples (VB and C#) it is used like this. Maybe this is just .net being new to me... but any help/suggestions is welcome. |
Re: powershell cmdlet (delphi.net)
As you know, .Create in Delphi invokes a constructor, whereas the C# code invokes a static method called "Create". To do this in Delphi, try
Delphi-Quellcode:
This will prevent the compiler from interpreting "Create" as a constructor call.
RunSpaceConfiguration.&Create;
|
Re: powershell cmdlet (delphi.net)
Thanks, didn't realise that difference (I really don't know much of c# and I'm taking my 1st steps into .net). Compiles perfectly now! :-D
|
Re: powershell cmdlet (delphi.net)
I ran into some more questions:
What does this do (is it some kind of try..finally construction?) and how to convert it?
Code:
On this line:
using (pipeLine)
Code:
I get an error on pl.Error.Count (again Syntax Highlighting shows the count property but Ide marks it as undeclared identifier).
if (pipeLine.Error != null && pipeLine.Error.Count > 0)
|
Re: powershell cmdlet (delphi.net)
I'm just giving this a little *push* anyone?
|
Re: powershell cmdlet (delphi.net)
Code:
is equivalent to
using (x) {
... }
Code:
try {
... } finally { x.Dispose(); } |
Alle Zeitangaben in WEZ +1. Es ist jetzt 11:07 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