Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Win32/Win64 API (native code) (https://www.delphipraxis.net/17-win32-win64-api-native-code/)
-   -   Prism powershell cmdlet (delphi.net) (https://www.delphipraxis.net/109405-powershell-cmdlet-delphi-net.html)

Remko 29. Feb 2008 18:21


powershell cmdlet (delphi.net)
 
I am trying to convert this sample code in C# (creates a mailbox in Exchange 2007) to Delphi.net (RAD Studio 2007).

I installed PowerShell and made a reference to the System.Management.Automation.dll. On this code:
Delphi-Quellcode:
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;
I get error [DCC Error] uMain.pas(41): E2003 Undeclared identifier: 'Create' on the line rc := RunSpaceConfiguration.Create;
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.

Khabarakh 29. Feb 2008 20:39

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:
RunSpaceConfiguration.&Create;
This will prevent the compiler from interpreting "Create" as a constructor call.

Remko 29. Feb 2008 20:43

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

Remko 1. Mär 2008 09:05

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:
using (pipeLine)
On this line:
Code:
 if (pipeLine.Error != null && pipeLine.Error.Count > 0)
I get an error on pl.Error.Count (again Syntax Highlighting shows the count property but Ide marks it as undeclared identifier).

Remko 3. Mär 2008 19:08

Re: powershell cmdlet (delphi.net)
 
I'm just giving this a little *push* anyone?

Dax 3. Mär 2008 19:50

Re: powershell cmdlet (delphi.net)
 
Code:
using (x) {
  ...
}
is equivalent to
Code:
try {
  ...
} finally {
  x.Dispose();
}


Alle Zeitangaben in WEZ +1. Es ist jetzt 14:47 Uhr.

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