你的类型弄错了,
var
   WndHandle : integer;
begin
   WndHandle := FindWindow(Nil,'计算器');
   IF WndHandle <> 0 then
      begin
         BringWindowToTop(WndHandle);
         ShowWindow(WndHandle,SW_RESTORE);
      end
   else
      begin
         WinExec('C:\WINDOWS\CALC.EXE',SW_SHOW);
      end;
end;

解决方案 »

  1.   

    winexec('c:\windows\notepad.exe c:\windows\desktop\abc',sw_show);
      

  2.   

    为什么不用ShellExecute,或者ShellExecuteEx,这两个函数可比WinExec强多了。
    不过你的错误应该是类型不匹配,你可以将String类型进行转换,转换成PChar类型的数据,这样就可以了
    var 
     a:string;
    a[1]就可以了。
      

  3.   

    很显然你在前面定义了一个String类型的变量,但是Winexec的Path参数需要的是一个Pchar类型的参数。所以就[Error] readbook.pas(43): Incompatible types: 'String' and 'PChar'
    应该先转变为PChar类型。
    Delphi封装后的WindowsAPI函数里面输入的参数都是PChar型,因为WindowsApi使用C写的,但是C没有String类型,用的字符串数组。
      

  4.   

    var filename:string;
    begin
    filename:='you file name ';
    shellexecute(0,nil,pchar(filename),nil,nil,sw_normal);
    end;