Avoid Access Violation Error from OpenDialog (TOpenDialog) / SaveDialog (TSaveDialog)
By Hamuro at 24 July, 2008, 10:53 am
Whe I use OpenDialog (TOpenDialog), SaveDialog (TSaveDialog), OpenPictureDialog (TOpenPictureDialog), or SavePictureDialog (TSavePictureDialog), on Delphi 7 or Turbo Delphi Explorer running on Windows Xp Sp2, I always get access violation error (run time error) after I open the dialog box for second time. At first time the application run, it’s OK to open and browse the file using the dialog but when I try to browse a file for second time, I always get this error: “First chance exception at 0x77E538B2 . Exception class EAccessViolation with message ‘Access violation at address 00408F02 in module ‘myapp.exe’. Read of address 00000000′. Process myapp.exe (0xDD8)” or simply “access violation of 0×77461340: read of address 0×00000014 process stopped”.
After hours of searching the internet, I finally find the solution: Add ActiveX in the uses part of implementation section of the main form (the form that run first). And add edit the end of that unit to include initialization and finalization. The original code of the main form will look like below:
uses Unit1, Unit2,…..;
{$R *.dfm}
…. {your codes}
…. {your codes}
…. {your codes}
end.
Add the ActiveX in uses and Initialization-finalization before the end. as shown below:
uses ActiveX, Unit1, Unit2,…..;
{$R *.dfm}
…. {your codes}
…. {your codes}
…. {your codes}
initialization
OleInitialize(nil);
finalization
OleUninitialize
end.
This trick can also be applied to Delphi 4,5,6 (TOpenPictDialog/TSavePictDialog), I hope this helps. Happy coding for everyone!










No comments yet.