Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > General

Lost Password?

Thread Tools Display Modes
Old 04-21-2007, 05:29 AM
Simon180 Simon180 is offline
Senior Member
Join Date: Dec 2003
Posts: 187
Default VB To Delphi Help!

I been trying to convert abit of code from VB to delphi with no luck so am wondering if anyone can help me?

Private Sub cmdOpen_Click()

On Error GoTo errhandle
Shell ("C:\Program Files\Silkroad\sro_client.exe " & txtNumber.Text & " /18 0 0")


newpath = InputBox("I'm sorry, sro_client.exe not found on default location, please specify another location:", "Error!", "C:\Program Files\Silkroad\sro_client.exe")

Shell (newpath & " " & txtNumber.Text & " /18 0 0")

End Sub
and here my delphi convert

procedure TForm1.cmdOpenClick(Sender: TObject);
newpath: String;
Label errhandle;

Shell( 'C:\Program Files\Silkroad\sro_client.exe '+txtNumber.text+' /18 0 0');


newpath := InputBox( 'I ''m sorry, sro_client.exe not found on default location, please specify another location:' , 'Error!' , 'C:\Program Files\Silkroad\sro_client.exe' );

Shell( newpath+' '+txtNumber.text+' /18 0 0');


my problem is I can not work out how to get the Shell funcations working like the vb code can anyone help please?thanks alot
Reply With Quote
Old 04-21-2007, 06:27 AM
paulholden paulholden is offline
Senior Member
Join Date: Jan 2001
Posts: 714
Default RE: VB To Delphi Help!

You can use the WinExec function like so;
WinExec(PChar(newpath), SW_SHOW);
Your try..except statement won't work as you're intending either. You should use the FileExists function to check whether the executable exists before trying to run it.

[sup]Hope that helps, please 'Accept as Answer' it if does[/sup] :^D
Reply With Quote
Old 04-21-2007, 10:35 PM
digitiger digitiger is offline
Senior Member
Join Date: Jan 2001
Posts: 716
Default RE: VB To Delphi Help!

if the only problem you are expecting is missing file then why not check for the existence of file before executing it.

you can do it as follows

if FileExists(newpath) then
WinExec(PChar(newpath), SW_SHOW);

Alternatively, you can react based on the result of WinExec function as below

if WinExec(PChar(newpath), SW_SHOW) < 31 then

you may note that the if result of WinExec function is less then 31 then it relates to unavailability of executable for one reason or the other for execution.

Hope it helps and if it does then do accept the answere

hope it helps
Reply With Quote
Old 04-22-2007, 06:17 AM
MrBaseball34 MrBaseball34 is offline
Senior Member
Join Date: Jan 2001
Posts: 7,260
Default RE: VB To Delphi Help!

Furst off, let me say that I would NEVER suggest using a
depricated function such as WinExec. This is the proper
Delphi way of doing this:

uses ..., ShellApi;

procedure TForm1.BtnOpen_Click(Sender: TObject);
sei: TShellExecuteInfo;
SFileName: String;
newpath: String;
ZeroMemory(@sei, sizeof(sei));
SetLength(sSysDir, MAX_PATH);
SFileName := 'C:\Program Files\Silkroad\sro_client.exe';

// Check if the file exists
if not FileExists(sFileName) then
// tell them it has not been found
if MessageBox(0, 'I''m sorry, sro_client.exe not '+
'found on default location, please '+
'specify another location.',
MB_ICONERROR or MB_OK) = mrOK then
// set the initialdir of the OpenFileDialog
OpenDialog1.InitialDir := C:\Program Files\Silkroad;
// if they select it, then set sFileName to the
// file returned from the dialog
if OpenDialog1.Execute then
sFileName := OpenDialog1.FileName;

// use ShellExecuteEX to run it, first fill
// the TShellExecuteInfo structure

with sei do
cbSize := SizeOf(sei);
Wnd := Form1.Handle;
lpVerb := 'open';
lpFile := PChar('SFileName');
lpParameters := PChar(edtNumber.Text + '/18 0 0');
lpDirectory := PChar(ExtractFilePath(sFileName));

Hook'Em Horns!

2005 College Football National Champions
2005 College Baseball National Champions
Reply With Quote

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump

All times are GMT. The time now is 02:14 AM.

Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2019, vBulletin Solutions, Inc.