Discussion:
Delphi can suck sometimes
(too old to reply)
bok
2013-10-21 08:58:40 UTC
Permalink
Raw Message
The code below is PURPOSELY written badly only to facilitate brevity, so don't
comment on it. What I AM venting about is the fact that what makes this code work in XE is that you have to send a pchar to Runit, but declare that what Runit is receiving is a string.

Yes; I know it is a Unicode thing!
Yes;I know that there are probably workarounds!
MY point is that this is crazy!!! I shouldn't have to "roll my own" solution
to so basic a task.

Do you know why Delphi never kicked VB or C in the ass? Two reasons: poor documentation and this kind of bullshit!!

Just my two cents
Thanks
/////////////////////////////////////////////////////
Procedure runit(Exe:string);
var
Si:TStartupInfo;
Pi:TProcessInformation;
begin
FillChar(Si,SizeOf(TStartupInfo),#0);
FillChar(Pi,SizeOf(TProcessInformation),#0);
Si.cb := SizeOf(TStartupInfo);
CreateProcess(nil,PChar(Exe),nil,nil,False,1049152,nil,nil,Si,Pi);
end;

procedure TForm1.Button1Click(Sender:TObject);
begin
runit(pchar('C:\Windows\Notepad.EXE'));
end;
Juha Piispa
2013-10-21 16:04:42 UTC
Permalink
Raw Message
Post by bok
The code below is PURPOSELY written badly only to facilitate brevity, so don't
I do not usually run other process from Delphi, but this has worked
fine since Delphi 7 and compiler also in XE2 and soon XE5..

procedure TMainForm.OpenDatafile(S: String);
Var I : Integer;
begin
If (S = '') Then ShowMessage('No file or URL !!!????')
Else Begin
I := ShellExecute(Handle,'open',PChar(S),nil,nil,sw_ShowNormal);
If (I < 32) Then ShowMessage('Could not do it :
'+IntToStr(I)+'.');
End;
end;

And this I have used to run some BAT/CMD stuff.. A bit cleaned sample
from my code that has been used in XE2..

procedure TDTW_SchedulerForm.BitBtn1Click(Sender: TObject);
Var Apu:String;
I : Integer;
begin
Apu:='F:\Data\Siirto\Aja.bat';
I := ShellExecute(Handle,'open',PChar(Apu),nil,nil,sw_ShowNormal);
If (I < 32) Then Loki.Lines.Add('Error: '+IntToStr(I)+'.');
end;


Regards, Qapla'
Juha Piispa

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Juha Piispa
Moonsoft OY

Loading...