Solved

c++ beginner (Bbuilder)

Posted on 2000-04-05
2
370 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
Comment Utility
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
Comment Utility
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

762 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now