0

i can't execute my program in lazarus does the lazarus support the wintypes and winprocs

base.pas (2,13) Fatal: Can not find WinTypes used by eg the Project Inspector.

program ex;
uses Wincrt,WinTypes, WinProcs;
var
  ch:string;

procedure exe (che:string);
begin
  writeln('ecrire ch');
  readln(che);
  if ch ='oui' then
  begin
    WinExec('cmd /k "C:\TPW\exercice\project\site.html"', SW_NORMAL);
  end;
end;

begin
  exe(ch);
end.
Anton Shchyrov
  • 285
  • 3
  • 15

1 Answers1

-1

WinExec function is obsolete. Use ShellExecute instead

program ex;

uses
  Windows,   // for constant SW_NORMAL
  ShellApi;  // for function ShellExecute

procedure exe;
var
  che: string;
begin
  writeln('ecrire ch');
  readln(che);
  if ch ='oui' then
  begin
    ShellExecute(0, 'open', 'C:\TPW\exercice\project\site.html', nil, nil, SW_NORMAL);
  end;
end;

begin
  exe;
end.
Anton Shchyrov
  • 285
  • 3
  • 15
  • AFAICT, the question is about the old WinTypes and WinProcs units, not about WinExec. That still exists, but you are right, it is obsolete. These days, the preferred way is CreateProcess, not ShellExecute. – Rudy Velthuis Oct 09 '18 at 06:58
  • @rudy Not really. CreateProcess is used to create processes. ShellExecuteEx is used to invoke shell verbs. In this case we probably need to invoke a shell verb. – David Heffernan Oct 09 '18 at 07:29
  • @David: WinExec usually executes a program, not verbs (like 'open x.pdf'), so the direct modern day equivalent is, AFAICT, CreateProcess. But you are right, in the question, the WinExec is used to somehow emulate what ShellExecute does, using 'cmd /k'. – Rudy Velthuis Oct 09 '18 at 08:30