Solved

c++ beginner (Bbuilder)

Posted on 2000-04-05
2
377 Views
Last Modified: 2012-05-04
Hi, I'm new in c++ Builder and I have following problem
In Delphi I declared public procedures & functions in public part of declarations and then later in code I wrote whole stuff so I'm able to acces these proc & functions form another forms

In builder I found .h files and i added function declaration in public part and then a wrote function in .cpp file but when i try to use my function I'm getting Linker error

example

part of my test_.h file
--------------------------------------

class TForm1 : public TForm
{
__published:      // IDE-managed Components
        TButton *Button1;
        void __fastcall Button1Click(TObject *Sender);
private:      // User declarations
public:            // User declarations
      void  vca (int ulaz);//<------ my declaration
        __fastcall TForm1(TComponent* Owner);
};


and implemenation in test_.cpp
-----------------------------------

void vca(int ulaz) {
//do somthing here (later)
}


& I try to call my function on button click
------------------------

void __fastcall TForm1::Button1Click(TObject *Sender)
{
Form1->vca(5);
}


When i try to compile program result is:
---------------------------------------------------------------
[Linker Error] Unresolved external 'TForm1::vca(int)' referenced from C:\PROGRAM FILES\BORLAND\CBUILDER4\PROJECTS\TEST_.OBJ.

Or when i try to implement my function as

TForm1::vca(int ulaz)  {
}

error is
[C++ Error] test_.cpp(16): E2316 'TForm1::vca(int)' is not a member of 'TForm1'.


I'm begginer so plese try to give as much detaile's as possible.
Regards Vedran

0
Comment
Question by:xtvca
2 Comments
 
LVL 6

Accepted Solution

by:
DrDelphi earned 20 total points
ID: 2687650
Header://---------------------------------------------------------------------------
#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published:      // IDE-managed Components
    TButton *Button1;
    void __fastcall Button1Click(TObject *Sender);
private:      // User declarations
public:            // User declarations
     void __fastcall DoSomething();
     __fastcall TForm1(TComponent* Owner);

};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif

CPP file:

//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
    : TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::DoSomething()
{
  ShowMessage("Dave was here");
}
void __fastcall TForm1::Button1Click(TObject *Sender)
{
  DoSomething();
}
//---------------------------------------------------------------------------





You'll note that I use __fastcall and that I reference TForm1 when implemtning the function:

void __fastcall TForm1::DoSomething()


Good luck!!



0
 

Author Comment

by:xtvca
ID: 2687866
This was great.
Thanks

You know I posted same question on c++ section but the answer was not at all good as this

Wll look like the Delphi folks rules in quality/support/speed matter.

RegarDs,
Vedran

0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

822 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question