AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

powershell cmdlet (delphi.net)

Ein Thema von Remko · begonnen am 29. Feb 2008 · letzter Beitrag vom 3. Mär 2008
Antwort Antwort
Benutzerbild von Remko
Remko

Registriert seit: 10. Okt 2006
Ort: 's-Hertogenbosch, Die Niederlande
222 Beiträge
 
RAD-Studio 2010 Arc
 
#1

powershell cmdlet (delphi.net)

  Alt 29. Feb 2008, 18:21
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.
  Mit Zitat antworten Zitat
Benutzerbild von Khabarakh
Khabarakh

Registriert seit: 18. Aug 2004
Ort: Brackenheim VS08 Pro
2.876 Beiträge
 
#2

Re: powershell cmdlet (delphi.net)

  Alt 29. Feb 2008, 20:39
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
RunSpaceConfiguration.&Create; This will prevent the compiler from interpreting "Create" as a constructor call.
Sebastian
Moderator in der EE
  Mit Zitat antworten Zitat
Benutzerbild von Remko
Remko

Registriert seit: 10. Okt 2006
Ort: 's-Hertogenbosch, Die Niederlande
222 Beiträge
 
RAD-Studio 2010 Arc
 
#3

Re: powershell cmdlet (delphi.net)

  Alt 29. Feb 2008, 20:43
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!
  Mit Zitat antworten Zitat
Benutzerbild von Remko
Remko

Registriert seit: 10. Okt 2006
Ort: 's-Hertogenbosch, Die Niederlande
222 Beiträge
 
RAD-Studio 2010 Arc
 
#4

Re: powershell cmdlet (delphi.net)

  Alt 1. Mär 2008, 09:05
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).
  Mit Zitat antworten Zitat
Benutzerbild von Remko
Remko

Registriert seit: 10. Okt 2006
Ort: 's-Hertogenbosch, Die Niederlande
222 Beiträge
 
RAD-Studio 2010 Arc
 
#5

Re: powershell cmdlet (delphi.net)

  Alt 3. Mär 2008, 19:08
I'm just giving this a little *push* anyone?
  Mit Zitat antworten Zitat
Dax
(Gast)

n/a Beiträge
 
#6

Re: powershell cmdlet (delphi.net)

  Alt 3. Mär 2008, 19:50
Code:
using (x) {
  ...
}
is equivalent to
Code:
try {
  ...
} finally {
  x.Dispose();
}
  Mit Zitat antworten Zitat
Antwort Antwort


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 22:48 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