Hi I have learnt a great deal about using functions here. Many things I have learnt are:- - Function return value from another form - Function return value from another formless unit
This time, I want functions to get the quote from formless unit THROUGH another form.
Using these methods above, I tried getting the functions to return from formless unit THROUGH another form. It seems that I was not able to get it working properly.
Unit1.h
//---------------------------------------------------------------------------
#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include <System.Classes.hpp>
#include <Vcl.Controls.hpp>
#include <Vcl.StdCtrls.hpp>
#include <Vcl.Forms.hpp>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // IDE-managed Components
TButton *Button3;
TLabel *Label3;
void __fastcall Button3Click(TObject *Sender);
private: // User declarations
public: // User declarations
__fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif
Unit1.cpp
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
#include "Unit2.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
extern String getQuote();
String quote1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button3Click(TObject *Sender)
{
quote1 = Form2->getQuote();
Label3->Caption = quote1;
}
//---------------------------------------------------------------------------
Unit2.h
//---------------------------------------------------------------------------
#ifndef Unit2H
#define Unit2H
//---------------------------------------------------------------------------
#include <System.Classes.hpp>
#include <Vcl.Controls.hpp>
#include <Vcl.StdCtrls.hpp>
#include <Vcl.Forms.hpp>
extern String FindQuote();
//---------------------------------------------------------------------------
class TForm2 : public TForm
{
__published: // IDE-managed Components
private: // User declarations
public: // User declarations
__fastcall TForm2(TComponent* Owner);
String getQuote();
};
//---------------------------------------------------------------------------
extern PACKAGE TForm2 *Form2;
//---------------------------------------------------------------------------
#endif
Unit2.cpp
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit2.h"
#include "Unit3.h"
extern String FindQuote();
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm2 *Form2;
//---------------------------------------------------------------------------
__fastcall TForm2::TForm2(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
String TForm2::getQuote()
{
return FindQuote();
}
//---------------------------------------------------------------------------
Unit3.h
//---------------------------------------------------------------------------
#ifndef Unit3H
#define Unit3H
//---------------------------------------------------------------------------
// declare the function here in the header file.
String FindQuote();
#endif
Unit3.cpp
//---------------------------------------------------------------------------
#pragma hdrstop
#include "Unit3.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
String FindQuote()
{
return "He with whom neither slander that gradually soaks into the mind, nor statements that startle like a wound in the flesh, are successful may be called intelligent indeed.";
}
I got error "
[bcc32 Error] Unit3.h(11): E2141 Declaration syntax error
Full parser context
Unit3.cpp(5): #include Unit3.h
[bcc32 Error] Unit3.cpp(14): E2238 Multiple declaration for 'String'
[bcc32 Error] Unit3.h(11): E2344 Earlier declaration of 'String'
[bcc32 Error] Unit3.cpp(14): E2141 Declaration syntax error
". How to fix it?