This form parameters are difficult!

I've tried to change a parameter of form(Form1 here, TForm1 class) and the errors pops.
Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop
#include <math.h>

#include "UnitEnergy.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "UnitEnergy"
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------

bool count=0;


//some code that you don't need


void __fastcall TForm1::Button2Click(TObject *Sender)
{
if(count==true)
{
Memo2->Visible=true;
Label1->Visible=true;
TForm::TForm1->Width=1146;//the problem Undefined symbol 'TForm1'
count=false;
}
else
{
Memo2->Visible=false;
Label1->Visible=false;
TForm1::TForm->Width=579;//the problem Undefined symbol 'TForm' 
count=true;
}
}
//--------------------------------------------------------------------------- 
TForm::TForm1 is not a variable. If Width is part of the encompassing class you access it like so:

TForm::Width=1146; // Note: Width needs to be part of TForm

this->Width=1146;

Width=1146;
Look at line 12: TForm1 *Form1;

Form1 is a pointer to the form object.

Your code should look like this:
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
void __fastcall TForm1::Button2Click(TObject *Sender)
{
    if(count==true)
    {
        Memo2->Visible=true;
        Label1->Visible=true;
        Form1->Width=1146;
        count=false;
    }
    else
    {
        Memo2->Visible=false;
        Label1->Visible=false;
        Form1->Width=579;
        count=true;
    }
}


Also, if your application has only one form, you can often omit the Form1-> and simply put Width=1146;. Though I don't necessarily recommend that.

Anyway, this gets easier with practice, trust me.
The Width is a parameter of Form1. Parameters displays as:'->'. What this line means?
extern PACKAGE TForm1 *Form1;
Packages are the way in which C++ builder handles its various components.
http://stackoverflow.com/questions/16347137/what-is-the-meaning-of-extern-package-tmyform-myform
Thanks programmers! Goodbye! See you next time!
Topic archived. No new replies allowed.