-2

So, here's my code:

Procedure exec;
uses
    ShellApi;
begin
try
ShellExecute( 0, 'Open', 'C:\ParamReport.Txt', nil,nil, SW_NORMAL);
except
ShowMessage('failed');
end;
end;

I am attempting to execute an external program, (regardless of type), within Altium Designer 2013 (13.3).

There is a basic editor within this program that I am using. Apparently, out of all of it's scripting documentation, it fails to mention which version of DelphiScript it uses in its editor. This is frustrating because as I copy and paste (working) code into the editor and try to run it - I run into many errors.

On the current code I get this error: "Undeclared Identifier: SW_NORMAL"

also, I desire to use the ".Split()" command. However, this apparently requires a "PChar" - which throws this error:"Undeclared Identifier: PChar"

I am running Windows 7 Pro 64

Please help. Thank you!

* EDIT *

I have already attempted "SW_SHOWNORMAL" - this produce same error.

* EDIT #2 *

I changed:

ShellExecute( 0, 'Open', 'C:\ParamReport.Txt', nil,nil, SW_NORMAL);

to:

ShellExecute( 0, 'Open', 'C:\ParamReport.Txt', nil,nil, 1);  

via Andreas Rejbrand's recommendation and I found that a new error was thrown.

"Undeclared Identifier: ShellExecute"

Now im really confused.

Roddy
  • 66,617
  • 42
  • 165
  • 277
  • You meant to write `SW_SHOWNORMAL`. – TLama Jan 08 '14 at 21:01
  • @TLama: Both `SW_NORMAL` and `SW_SHOWNORMAL` have value `1`. But `SW_SHOWNORMAL` is the normal (sorry about that...) one to use. – Andreas Rejbrand Jan 08 '14 at 21:03
  • Try `1` instead of the constant. – Andreas Rejbrand Jan 08 '14 at 21:05
  • @TLama: I just edited my post. I have already attempted both SW_SHOWNORMAL and SW_NORMAL. – ChrisPrattmt Jan 08 '14 at 21:06
  • @Andreas Rejbrand: I changed the 0 to 1 and found the same error. That is, if you are referring to the first parameter in ShellExecute(). – ChrisPrattmt Jan 08 '14 at 21:08
  • @ChrisPrattmt: No, the constants `SW_NORMAL` and `SW_SHOWNORMAL` have the value `1`, so if for some reason these constants are not defined in your environment, you can simply pass a `1` instead of `SW_NORMAL` or `SW_SHOWNORMAL`. (The first argument is the HWND of the parent window; see [the documentation](http://msdn.microsoft.com/en-us/library/windows/desktop/bb762153(v=vs.85).aspx).) – Andreas Rejbrand Jan 08 '14 at 21:10
  • 2
    Please show the real code. Fake code does not inspire confidence. Also, it would help if the text matched the code. What you describe seems utterly unrelated to the code. Finally, ShellExecute does not raise exceptions. – David Heffernan Jan 08 '14 at 21:14
  • @DavidHeffernan : This is the "real code" that I am copying and pasting from my editor. All I want to do is execute a program within delphiscript from within altium designer editor. Perhaps the version of delphi that the editor has does not support ShellExecute... I am telling you how it is. The editor throws the said error at the point where the ShellExecute code line exists. please be more helpful... – ChrisPrattmt Jan 08 '14 at 21:42
  • The uses is inside the procedure. Not in Delphi it isn't. – David Heffernan Jan 08 '14 at 23:55
  • The compiler was going to get to the fact that `ShellExecute` was not recognised. But it found the other error first. When you fixed that, the next error, namely `ShellExecute` not existing, was found. – David Heffernan Jan 09 '14 at 11:55

3 Answers3

1

I can't speak for Delphiscript, but in Delphi the SW_... constants are defined in the Windows unit:

uses
  ShellApi, Windows;

Check if Delphiscript has a Windows unit.

PChar is built in to the Delphi compiler, so if PChar does not compile in Delphiscript then maybe Delphiscript does not support null-terminated character strings only Delphi-style strings, or maybe there is another unit you can use to access PChar.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
  • Ah! I had not supposed that Delphi and Delphiscript were 2 different languages... i shall search uncle Google more concisely... – ChrisPrattmt Jan 08 '14 at 21:45
  • 3
    Delphi is a product originally created by Borland and now maintained by Embarcadero. DelphiScript is a scripting language used by Altium that uses a Delphi-like syntax, but it is not actually Delphi. Refer to Altium's [DelphiScript documentation](http://techdocs.altium.com/display/ADRR/DelphiScript) for more details. – Remy Lebeau Jan 08 '14 at 22:05
0

It looks very much as though DelphiScript does not support calls to the Windows API using ShellAPI. In which case your code cannot ever work. I suggest that you request technical support from Altium.

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
0

This worked for me using Delphi XE7

uses

Winapi.Windows, ShellApi, ...

Whosml
  • 11
  • 2