Delphi executes an external program, and when the external program finishes, the Delphi program responds immediately

Source: Internet
Author: User

Need to refer to SHELLAPI unit;
Procedure Tform1.button1click (Sender:tobject); var seinfo:tshellexecuteinfo; Exitcode:dword; Executefile, paramstring, startinstring:string; Begin Executefile: = ' c:\Windows\system32\Calc.exe '; Fillchar (Seinfo, SizeOf (seinfo), #0); Seinfo.cbsize: = SizeOf (Tshellexecuteinfo); With Seinfo do begin fmask: = see_mask_nocloseprocess; Wnd: = Application.handle; Lpfile: = PChar (Executefile); Paramstring can contain the application parameters//Lpparameters: = PChar (paramstring); startinstring Specifies the name of the working Directory.if ommited, the current directory is used. Lpdirectory: = PChar (startinstring); Nshow: = Sw_shownormal; End If ShellExecuteEx (@SEInfo) then BEGIN repeat application.processmessages; GetExitCodeProcess (seinfo.hprocess, ExitCode); If ExitCode = Still_active then Sleep (500); Until (ExitCode <> still_active) or application.terminated; ShowmesSage (' Calculator terminated '); End Else ShowMessage (' Error starting calc! '); End

Delphi executes an external program, and when the external program finishes, the Delphi program responds immediately

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.