VIDISONIC

Hardware & Software Design Resources

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!

Artificial Neural Network Shell: A Case Study of Object Oriented Concept in Old Style Structured Programming Practice

Background
People who familiar with structured programming style and not yet with object oriented programming (OOP) style often think that OOP is useless for them, because almost everything done with OOP can be done with old-structured style. In my opinion, they insist to use their old style programming is not caused solely by not understanding OOP concept and practice, but also because they are not familiar with advanced programming with their own structured style.

The Case
If they have long experience in structured programming, I believe that they should have implemented the concept of OOP, although they don’t realize it. Let’s study a case when we have to implement a complex software using traditional structured style: a back-propagation neural network shell.

Let’s define the requirement of the shell:

  1. The number of layer is configurable
  2. The number of neuron on each layer is configurable
  3. The activation function on each layer is configurable
  4. The learning rate of the network is configurable
  5. The whole system can be arranged from many neural network subsystem, which each subsystem has the properties defined in requirement 1, 2, 3, and 4 independently configurable.

When we look at the requirement no. 1-4, you can implement the coding the source code in structured style easily. Think about no. 5 requirement, now you’ll realize that the work will be much complicated.

Implementation Using Functions and Structure
The modular requirement of the software force you to think about object concept in your mind, because each module can be viewed as one class with different property values. Let’s go to code in structured style: use functions and structures.

Lets make a function called CreateANN:

CreateANN(ANN_STRUCT* ann_object, int number_of_layers, int* size_each_layers)

A structur ANN_STRUCT is needed to manage the variables used in the network, and the function CreateANN initialize all variables in the ANN_STRUCT instance. The function CreateANN is similar to constructor in the OOP concept.

After initialization, you can create many functions to operate the neural network. Look at some functions examples you can create:

  • TrainTheNeural Network(ANN_STRUCT* ann_object, double* input_pattern, double* output_pattern, double minimum_error, int max_number_of_iteration)
  • GetNeuralOutput(ANN_STRUCT* ann_object, double* input, double* output)
  • SaveTheWeightToFile(ANN_STRUCT* ann_object, char* file_name)

You can see that these functions are similar to class’s method/function members in OOP concept. Using functions and structure, now you can build a modular artificial neural network by cascading the networks, feeding one network’s output to other network’s input. Let’s stop talking about neural network because this article is not intended to show you how to code a neural network, only just to show that the old structured programming style practice, when facing a complicated task, should have been common to implement something close to OOP concept.

Conclusion
Studying the case of a complex software design, we can see that the concept of object oriented programming can be found on traditional style practice. I hope everyone can now understand and take the benefit of object oriented programming style. Use the OOP technology, and now you’ll be more productive and your life would be easier. (Hamuro)