Avoid Access Violation Error from OpenDialog (TOpenDialog) / SaveDialog (TSaveDialog)
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!
Related posts:
- Access The Android Market From Your PC Recently Google just announced that the Android user can now download application from Android Market via your PC or laptops. They are now online to...
- South Korean Internet Access is 200x Faster Than The US The South Korea has succeed becoming a country with the fastest internet access in the world, they even beat the US. By the end of...
- Are We Gonna Run Out Of The IP Address? Vint Cerf, one of the designer that design the IP address protocol said that the total of IP address that were 4,3 billion address is...
- Reducing PCB Design Costs: From Schematic Capture to PCB Layout This application note talks about reducing PCB costs from schematic capture to PCB layout. The issues about how to reduce the cost of PCB designs...
- Introduction to Phase-Locked Loop System Modeling This application note talks about the Introduction to phase-locked loop system modeling. The issue about linear PLL model is presented after introduction. The main topic...