Access Violation ShellExecute in delphi7
Asked Answered
U

2

1

I am using ShellExecute the same way given below, to open a txt file in Delphi7, it gives me access violation in module BORdbk70.dll. Not sure what this issue is? I have added ShellApi in uses list.

//sAddr := 'www.google.com'; 
Above line does not gives any error but also not redirect to browser and 
  ShellExecute returns result as "5 = Windows 95 only: The operating system denied access to the specified file"

sAddr := 'c:\text\info.txt';
res := ShellExecute(Handle, nil, PChar(sAddr), nil, nil, SW_SHOW);
showmessage(inttostr(res));
Underground answered 24/3, 2015 at 8:35 Comment(6)
It's a pure debugger issue. Nothing much to worry about. You shouldn't use ShellExecute anyway because it doesn't report errors properly. Use ShellExecuteEx.Centerboard
And FWIW, you cannot possibly know what error ShellExecute does return since your code ignores the return value.Centerboard
@DavidHeffernan - Thanks David, but now the other question arises that how it was running previously and suddenly started behaving like this. There is no change in system and/or in code as well. I have also visited this page - qc.embarcadero.com/wc/qcmain.aspx?d=11751Underground
You are talking about a >10 year old IDE. I think you'll just have to put up with it. At the very least, see if using ShellExecuteEx, which is a much better option anyway, somehow avoids the problem.Centerboard
@DavidHeffernan - Yeah true :). because when I run my program with administrative rights this function got executed successfully. Issue is coming with debugging only which you have also mentioned. Thanks again.Underground
possible answer: #50861606Kainite
E
0

This example that I wrote for you, working good (without error). I tested with Delphi7 on Windows 8.1

You must know what is default application to open *.txt files in your Operation System. That application will try open your file. On my system for *.txt default application is Notepad++ and this example opened file info.txt in Notepad++

Full source (pas) code:

unit Unit1;
interface
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ShellApi;
type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
  sAddr : String;
  res : Integer;
begin
  sAddr := 'c:\text\info.txt';
  res := ShellExecute(Handle, 'open', PChar(sAddr), nil, nil, SW_SHOW);
  showmessage(inttostr(res));
end;
end.

This example working good with admin and normal user rights.

Etienne answered 28/9, 2016 at 9:49 Comment(0)
D
0
var
file:string;
exe_start_map:string;
 begin
  exe_start_map:=(ExtractFileDir(Application.ExeName));
  file:=exe_start_map+'\samplefile.txt';
  ShellExecute(handle,'open',pchar(file),'','',SW_SHOWnormal);
 end;

you must add ShellApi in uses list

Deluca answered 22/2, 2019 at 15:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.