Testing Algorithms of classes, functions, component events
Create a function !
This is also a way to create a function or an event and hardcode
it into the C++ Builder TForm::TForm1 class
I wanted to show a message in response to pretty well any
event which could take place in any of the ready made
palette acquired C++ Builder visual or non-visual components.
Here I have used it in response to a Button1 Click event
To simulate and test with this code example here are
the basics requirements.
Create a windows application - leave names etc to defaults
Use Form1 for this test
Add a button to the form - leave assignments as default.
Add other classes if you like
The steps for the Forms assignments :
1): Define the purpose for the function
: To show or send a message when some event or action
: has taken place in an application.
2): Unit1.h function declaration is placed in either the
private or public part of the TForm1 class
1 2 __public
3 __fastcallvoid ShowAmessage();
3): Unit1.cpp definitions are placed following __fastcall TForm1 :
or at the end of all the code in the .cpp file.
// This is the event or function that is called
4 5 void__fastcall TForm1::ShowAmessage()
7 ShowMessage("This is a message");
4): Where to place the function call code
Finally place the function into the Button1 Click event
and click it.
What the function does:
Any message you create will appear
The declarations worked also without the use of __fastcall
So, you can use fastcall or not - depending if it is just a function
The .h declaration works in the private section as well but not
in the published. I believe it would work it I had used this format
as an event for a component I had written. Something this little
bit of code can provide for very easily.
The code could also be used for testing purposes : such as
determining just when events are firing or what the results
are given a firing. The code could also be extended to write
to a log file for a hardcopy reference of events and happenings.
This code may also work to track the actions of a class/object
functionality at runtime.
Add other development scenerios as you like.
Happy programming !
David W. Stubbs