Delphi Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming Languages - MoreDelphi Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old January 2nd, 2004, 06:51 PM
jake8 jake8 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Posts: 37 jake8 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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

Reply With Quote
  #2  
Old May 31st, 2004, 06:38 AM
Canderel Canderel is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 40 Canderel User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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.

Reply With Quote
  #3  
Old June 1st, 2004, 04:44 AM
jake8 jake8 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Posts: 37 jake8 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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?

Reply With Quote
  #4  
Old June 1st, 2004, 05:03 AM
Canderel Canderel is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 40 Canderel User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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(TComponentOwner);
  
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);


Reply With Quote
  #5  
Old June 1st, 2004, 10:30 AM
jake8 jake8 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Posts: 37 jake8 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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?

Reply With Quote
  #6  
Old June 2nd, 2004, 01:07 AM
Canderel Canderel is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 40 Canderel User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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)

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreDelphi Programming > Function writing with Borland Builder C++

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap