views:

386

answers:

6

I have checked 100% I am closing all handles on a file I recently created. But when I call "opendialog.execute;" the dialog pop up as usual but on the mouse over hint of a recently created file the entire thing crashes with a out of bounds error.

I know this is not any of my out of bounds as if I open the file without causing a (onhint) event there is no problem and hardcoding a list of filenames for testing showed that there was nothing wrong with opening or saving a file. Its purely on the onhint event of the open dialog. Like I said if I am quick or I use arrow keys there is nothing wrong with my program.

Whats more interesting is that it doesnt even happen 100% of the time about 70% which has led to me thinking I have fixed it several time if not only for a short amount of time. Does anyone know what could be happening? And if not how can I disable the onhint event?

as aked for the code not that helps at all

OpenDialog.execute;    // crashes here
if fileexists(form1.OpenDialog.FileName) then    
  form1.Address.Text:=form1.OpenDialog.FileName;

and the error link text

EDIT: ok i have some new information a new instance of opendialog still has the same issues. and more interestingly i seem to have solved the 30% issue its on hint of a file with a double tag for example "test.jpg.enc" the thing is its fine with it the first time it runs, and it only crashes on hint of these encoded files, but only if i have encoded that file white the applicatuion has benn open. for example if i encode it,, then try to decode and it crashes.. i can run it again and decode it fine,, but there is no problem with decoding and then encoding in one instance of the aplication.

+3  A: 

Are you sure an instance of form1 is created?

if yes:

Why dont you use like this:

OpenDialog.Options:=  OpenDialog.Options + [ofFileMustExist];

if OpenDialog.Execute then
  Address.Text:= OpenDialog.FileName

And use FastMM4, and define FullDebugMode in FastMM4.inc. This may help you to find the real problem

Cesar Romero
+3  A: 

First -- it is almost never necessary to refer to "form1.xxx" in your code, /especially/ if you are writing code in a method of Form1. I'd remove those references.

Then, I'd create as simple an application as possible -- a form, a TOpenDialog, and a button, and I'd try to write as little code as possible to open the file in question. If that works, try to figure out what the difference is between your simple app and your real app. If it fails, edit your question above with /all/ the code for the simple program that fails.

Nick Hodges
it is is a method that is not from a coponent in form1 so it dioes not recognise the objects on form1 unless i specify. adding on to your suggestion while it is good the opendialog only retains data such as filename...etc. a simple button on the form with code "opendialogtest.execute" also crashes..
Arthur
If /that/ is the case, then you /should/ make the method a method of the form.In other words, only very rarely should you ever call "form1.xxxxx"
Nick Hodges
As Nick says, it sounds like bad design, but in any case, it sounds like Form1 has not yet been created.
Mike Sutton
form1 has been created and working for some point as this error ONLY happens after i cause a onhint on a encoded file that has been created/modified since the application has benn open.
Arthur
+1  A: 

Two things:

Compile your application with Debug DCU's (Project / Options / Use Debug DCU's - then do a full build) and then see where the exception is occurring. This will give you some more information when and exception is occurring in vcl/rtl code. Post us the full error message and where in what unit it failed.

Second, and probably more importantly, is how the file behaves outside your application. You suggest it fails about 30% of the time, so every time after you save the file, browse to it in a regular explorer window and mouse over it there and see if the hint displays fine. Then open it in notepad. If both of those work, and then it fails in your application that would be interesting.

Also, when you are posting a follow up question to a previous question it is helpful if you link to the previous question so we can see what you previously tried.

Gook luck!

Jim McKeeth
+1  A: 

The error message is not a out of bounds but an access violation. This means you are accessing memory that is not yours to access. This happens mostly when a class variable (which is a pointer to a class) is not initialized or is already freed.

The code, which I presume is a method of form1, can use some change (which already is mentioned):

OpenDialog.execute;    // crashes here
if fileexists(OpenDialog.FileName) then    
  Address.Text := OpenDialog.FileName;

But what is OpenDialog, is it a component dragged to form1? In that case form1 is probably not initialized. But most likely is that OpenDialog is a local variable. In that case you can initialize it:

OpenDialog := TOpenDialog.Create;
try
  OpenDialog.execute;   
  if fileexists(OpenDialog.FileName) then    
    Address.Text := OpenDialog.FileName;
finally
  OpenDialog.Free;
end;
Gamecat
sorry for being a noob i havnt used this for long. what do i initilise opendialog as , i guessed it would be Topendialog but that left delphi expecting more after topendialog.create *some thing like not enough perameters)
Arthur
It probably expects a single parameter of type TWinControl, but you can pass in nil: OpenDialog := TOpenDialog.Create(nil);
Mike Sutton
A: 

Your comment to Nick Hodges' answer indicates that you are calling the OpenDialog of Form1 from outside Form1. This seems like a Bad Idea. Instead, a public method of Form1 could be called, and that method could manipulate the components of Form1. I have not tested your scenario, but it seems as though that could be causing your troubles.

Argalatyr
A: 

The solution for this was to use activeX, it appears there was a bug intorduced after SP2

uses ActiveX;

initialization OleInitialize(nil);

finalization OleUninitialize end.

oringinaly posted by the fox here

Arthur