dcsimg
Login | Register   
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


Tip of the Day
Language: Pascal
Expertise: Beginner
Mar 19, 1999

WEBINAR:

On-Demand

Application Security Testing: An Integral Part of DevOps


Executing a File Selected in Filelistbox

Question:
I am trying to work out the coding to execute a file that I select in my filelistbox in Delphi 4. Can you help me?

Answer:
You can refer to the online help for ShellExecute, or for a more robust methodology, use CreateProcess. Here's a wrapper for that:

procedure ExecNewProcess(ProgramName : String; 
                         Wait : Boolean);
var
  StartInfo  : TStartupInfo;
  ProcInfo   : TProcessInformation;
  CreateOK   : Boolean;
begin
  { fill with known state }
  FillChar(StartInfo,SizeOf(TStartupInfo),#0);
  FillChar(ProcInfo,
           SizeOf(TProcessInformation), #0);
  with StartInfo do begin
    cb := SizeOf(TStartupInfo);
    dwX := 10000;
    dwY := 10000;
    dwFlags := dwFlags OR STARTF_USEPOSITION;
  end;

  CreateOK := CreateProcess(nil, 
              PChar(ProgramName), nil, nil,False,
              CREATE_DEFAULT_ERROR_MODE AND (NOT 
              CREATE_NEW_CONSOLE) OR
              CREATE_NEW_PROCESS_GROUP OR 
              HIGH_PRIORITY_CLASS,
              nil, nil, StartInfo, ProcInfo);

  { check to see if successful }
  if CreateOK then
    if Wait then
      //may or may not be needed. Usually wait 
      //for child processes
      WaitForSingleObject(ProcInfo.hProcess, 
                          INFINITE);
end;
DevX Pro
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
×
We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.
Thanks for your registration, follow us on our social networks to keep up-to-date