Using elements of a Form within a function

Asked

Viewed 110 times

0

I am developing an application in C++ Builder that has a Form which contains elements such as ListBox, buttons, Labels, etc..

I can configure the events of each of these elements (onClick, onEnter, onExit...) inside a file .cpp, but when I try to create a function within this same file .cpp access the properties of the elements (Visible, Enabled, Caption, etc.) get an error:

"Undefined Symbol".

How do I use the elements contained in a Form within a function created by me.

Follow the problem code.

//Função criada por mim, dentro da Unit1.cpp que contem o Form1 no qual está o ListBox1

void funcao(AnsiString parametro){ 

 ...
 ListBox1->Items->Add("ItemParaListBox"); //Essa linha gera o erro "undefined symbol ListBox1"

}

//Função de fastcall realizada para edição de evento do elemento dentro da mesma Unit1.cpp

void __fastcall TForm1::BitBtn11Click(TObject *Sender){

...
ListBox1->Items->Add("ItemParaListBox"); //Funciona normalmente

}
  • If you do not put details of how you are using what becomes difficult to answer something.

  • Without having your code it is impossible to guess what the error is. Consider making a minimum verifiable example.

  • Apparently the problem is that its function is not a class method TForm1, and therefore cannot access the members of this class (among them, the ListBox1).

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.