#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2003
    Posts
    37
    Rep Power
    11

    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
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2004
    Posts
    40
    Rep Power
    10
    Hi jake.

    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.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2003
    Posts
    37
    Rep Power
    11
    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?
    Thanks............Jake
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2004
    Posts
    40
    Rep 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);

  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2003
    Posts
    37
    Rep Power
    11
    Hi,
    Thanks.
    Is the function defined in public so access by other functions is possible?
    Thanks............Jake
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2004
    Posts
    40
    Rep 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)

IMN logo majestic logo threadwatch logo seochat tools logo