我现在是德尔菲的初学者,我想学习这门语言,但我有错误,我不知道哪里有问题,如何解决它。这个例子,我把它从书到德尔菲。
误差
Pascal Engine.pas(41):E2250没有使用这些参数调用的“ShellExecute”重载版本
所有代码:
unit Engine;
interface
uses Windows, Classes, SysUtils;
type
TTemplate = array of String;
TEngine = class
private
FFileName : String;
FFileLines : TStringList;
protected
procedure Execute(Path : String); virtual;
public
Pattern : TTemplate;
Replace : TTemplate;
procedure Parse;
constructor Create(FileName : String);
destructor Destroy; override;
end;
implementation
{ TEngine }
uses ShellAPI; // włączenie modułu ShellAPI
constructor TEngine.Create(FileName : String);
begin
FFileName := FileName; // przypisanie wartości parametru do
FFileLines := TStringList.Create; // utworzenie typu TStringList
FFileLines.LoadFromFile(FileName); // załadowanie zawartości
inherited Create;
end;
destructor TEngine.Destroy;
begin
FFileLines.Free; // zwolnienie typu
{ zwolnienie tablic }
Pattern := nil;
Replace := nil;
DeleteFile('temporary.html'); // wykasowanie pliku tymczasowego
inherited; // wywołanie destruktora klasy bazowej
end;
procedure TEngine.Execute(Path: String);
begin
// otwarcie pliku w przeglądarce Internetowej
ShellExecute(0, 'open', PChar(Path), nil, nil, SW_SHOW);
end;
procedure TEngine.Parse;
var
i : Integer;
begin
for I := Low(Pattern) to High(Pattern) do
{ zastąpienie określonych wartości w FFileLines }
FFileLines.Text := StringReplace(FFileLines.Text, Pattern[i],
Replace[i], [rfReplaceAll]);
FFileLines.SaveToFile('temporary.html');
Execute('temporary.html');
end;
end.带有错误的位置
ShellExecute(0, 'open', PChar(Path), nil, nil, SW_SHOW);图像误差

Ctrl +单击
[SuppressUnmanagedCodeSecurity, DllImport(shell32, CharSet = CharSet.Auto, SetLastError = True, EntryPoint = 'ShellExecute')]
function ShellExecute(hWnd: HWND; Operation, FileName, Parameters,
Directory: string; ShowCmd: Integer): HINST; external;
[SuppressUnmanagedCodeSecurity, DllImport(shell32, CharSet = CharSet.Auto, SetLastError = True, EntryPoint = 'ShellExecute')]发布于 2013-04-23 09:43:15
看看ShellExecute在.net实现ShellAPI中的声明,我们可以清楚地看到该做什么。停止转换到PChar,编写如下代码:
ShellExecute(0, 'open', Path, '', '', SW_SHOW);到目前为止,我还没有意识到这一点,但是您从Delphi.net发出的Windows调用似乎使用了与其他.net语言相同的DllImport属性。我想这是有意义的,这些都是正常的p/调用调用,就像在C#互操作代码中所发现的那样。
有趣的是,您报告说,试图将nil传递给这些字符串参数之一会导致编译器错误。这意味着没有一种简单的方法可以将空指针传递给需要C字符串的API函数。您需要做的是使用一个重载的外部声明,该声明接收要传递Pointer给的参数的nil。
顺便提一下,Embarcadero开发人员在他们的DllImport声明中犯了一个错误。它们设置SetLastError = True,这对于没有设置线程最后错误值的ShellExecute来说是不正确的。
https://stackoverflow.com/questions/16164365
复制相似问题