The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages - More
> Delphi Programming
|
Function writing with Borland Builder C++
Discuss Function writing with Borland Builder C++ in the Delphi Programming forum on Dev Shed. Function writing with Borland Builder C++ Delphi Programming forum discussing Delphi related topics including Kylix, C++ Builder, and more. Delphi is a high-performance language, originally based on the PASCAL language.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

January 2nd, 2004, 06:51 PM
|
|
Contributing User
|
|
Join Date: Oct 2003
Posts: 37
Time spent in forums: 34 m 52 sec
Reputation Power: 10
|
|
|
Function writing with Borland Builder C++
I wish to write a function that does not activated by a component e.g. a
button.
The function is to be called when a button is called.
What is the best way to reference this function?
A portion of the code appears below
Code:
void __fastcall TForm1:Draw_tableClick(TObject *Sender)
{
nw();
switch (corner) {
case 'A': break;
case 'B': break;
case 'C': break;
case 'D': break;
default: break;
}
}
nw() and corner are declared in the header file. nw() is written in the main
unit.
Jake
__________________
Thanks............Jake
|

May 31st, 2004, 06:38 AM
|
|
Contributing User
|
|
Join Date: May 2004
Posts: 40
Time spent in forums: < 1 sec
Reputation Power: 10
|
|
Hi jake.
Quote: I wish to write a function that does not activated by a component e.g. a
button.
The function is to be called when a button is called.
What is the best way to reference this function?
A portion of the code appears below |
What do you mean by 'a button is called'? Does this mean a keyboard button, or a visual button?
Now, if I understand you correctly... you'd like to respond to a button (keyboard press), and do certain things accordingly.
switch (keyboardinput) {
case 'A'
etc...
You should check your control's events. There is (most of the time) an 'OnButtonPress" event. Doubleclick on that.
Then write your code. The variable Key that is sent up is the one that you will use to see what happens.
If you don't want the component to get the Key, change it to NULL before you end the method.
You can assign the same code to all the different components at designtime.
|

June 1st, 2004, 04:44 AM
|
|
Contributing User
|
|
Join Date: Oct 2003
Posts: 37
Time spent in forums: 34 m 52 sec
Reputation Power: 10
|
|
|
Hi,
Thanks for your response.
What I am trying to find out is how to write a function that is not associated with any button, or event. Note i am not talking about keyboard buttons. in Borland builder. how does one define it in the header etc?
|

June 1st, 2004, 05:03 AM
|
|
Contributing User
|
|
Join Date: May 2004
Posts: 40
Time spent in forums: < 1 sec
Reputation Power: 10
|
|
Typically you'd want to add something to the form's class (a outside method, that can access all of the var's inside the form etc.)
Lets say you have a whole lot of editboxes with numbers in it, and you want a function that can return you the total of these boxes.
in mainform.h
PHP Code:
class TMainForm : public TForm
{
__published: // IDE-managed Components
TEdit *Box1;
TEdit *Box2;
TEdit *Box3;
TEdit *Box4;
TEdit *TotalBox;
__fastcall BoxExit(TObject * Sender);
private: // User declarations
double total;
public: // User declarations
__fastcall TMainForm(TComponent* Owner);
double GetTotal(); // <--- Define it in Public
};
then in your mainform.cpp
PHP Code:
double Tmainform::GetTotal() // <--- This can happen anywhere
{
return StrToFloatDef(Box1->Text,0) +
StrToFloatDef(Box2->Text,0) +
StrToFloatDef(Box3->Text,0) +
StrToFloatDef(Box4->Text,0);
}
Then lets say when you exit any of the editboxes you have
PHP Code:
void __fastcall Tmainform::BoxExit(TObject * Sender)
{
total = GetTotal(); // <--- Call it from any other place that is in Tmainform
TotalBox->Text = FormatFloat("0.00",total);
}
|

June 1st, 2004, 10:30 AM
|
|
Contributing User
|
|
Join Date: Oct 2003
Posts: 37
Time spent in forums: 34 m 52 sec
Reputation Power: 10
|
|
|
Hi,
Thanks.
Is the function defined in public so access by other functions is possible?
|

June 2nd, 2004, 01:07 AM
|
|
Contributing User
|
|
Join Date: May 2004
Posts: 40
Time spent in forums: < 1 sec
Reputation Power: 10
|
|
|
I usually define it in public so that I can access it from other forms. You might have a different way to change the numbers in those editboxes, and then to be able to call them from elsewhere might be useful.
In this case however, you could define it as private too. Deciding what should be private and what public is a classic OOP question, but to me it's just a matter of practicality. (Coming from a delphi background)
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|