- Kod: Zaznacz cały
[BCC32 Error] pole_gry.cpp(52): E2268 Call to undefined function 'FindComponent'
Jak zdefiniować tą funkcję, aby działała?
[BCC32 Error] pole_gry.cpp(52): E2268 Call to undefined function 'FindComponent'
najprawdopodobniej problem polega na tym iz owa funkcaj to nie funkcja globalna a metoda klas komponentow ktore
void Funkcja(void)
{
FindComponent(...);
}
void Funkcja(void)
{
Form1->FindComponent(...);
}
//plik nagłówkowy np. Unit1.h
public:
void Funkcja(void);
//-----------------------------------------------
//plik źródłowy np. Unit1.cpp
void TForm1::Funkcja(void)
{
this->FindComponent(...);
}
void move(TButton *mob, int x, int y){
if (mob->Caption != "") {
TIniFile *Ini = new TIniFile("mobs.ini");
int ruch = Ini->ReadInteger(mob->Caption, "ruch", 0);
delete Ini;
dynamic_cast<TButton *>(FindComponent("p" + IntToStr(x) + IntToStr(y-ruch)))->Enabled = true;
dynamic_cast<TButton *>(FindComponent("p" + IntToStr(x) + IntToStr(y+ruch)))->Enabled = true;
dynamic_cast<TButton *>(FindComponent("p" + IntToStr(x-ruch) + IntToStr(y)))->Enabled = true;
dynamic_cast<TButton *>(FindComponent("p" + IntToStr(x+ruch) + IntToStr(y)))->Enabled = true;
}
}
public:
void move(TButton *mob, int x, int y);
void TForm1::move(TButton *mob, int x, int y)
{
if (!mob->Caption.IsEmpty()) // to jest równoznaczne z zapisem: if(mob->Caption != "")
{
String fileIni = ExtractFilePath(ParamStr(0)) + "mobs.ini";
TIniFile *Ini = new TIniFile(fileIni); // należy zastosować ścieżkę bezwzględną
int ruch = Ini->ReadInteger(mob->Caption, "ruch", 0);
delete Ini;
dynamic_cast<TButton *>(this->FindComponent("p" + IntToStr(x) + IntToStr(y-ruch)))->Enabled = true;
dynamic_cast<TButton *>(this->FindComponent("p" + IntToStr(x) + IntToStr(y+ruch)))->Enabled = true;
dynamic_cast<TButton *>(this->FindComponent("p" + IntToStr(x-ruch) + IntToStr(y)))->Enabled = true;
dynamic_cast<TButton *>(this->FindComponent("p" + IntToStr(x+ruch) + IntToStr(y)))->Enabled = true;
}
}
void TForm1::move(TButton *mob, int x, int y)
{
if (!mob->Caption.IsEmpty()) return; // return przerywa wykonywanie dalszych instrukcji i wyrzuca z funkcji
String fileIni = ExtractFilePath(ParamStr(0)) + "mobs.ini";
TIniFile *Ini = new TIniFile(fileIni); // należy zastosować ścieżkę bezwzględną
int ruch = Ini->ReadInteger(mob->Caption, "ruch", 0);
delete Ini;
dynamic_cast<TButton *>(this->FindComponent("p" + IntToStr(x) + IntToStr(y-ruch)))->Enabled = true;
dynamic_cast<TButton *>(this->FindComponent("p" + IntToStr(x) + IntToStr(y+ruch)))->Enabled = true;
dynamic_cast<TButton *>(this->FindComponent("p" + IntToStr(x-ruch) + IntToStr(y)))->Enabled = true;
dynamic_cast<TButton *>(this->FindComponent("p" + IntToStr(x+ruch) + IntToStr(y)))->Enabled = true;
}
Powrót do Ogólne problemy z programowaniem
Użytkownicy przeglądający ten dział: Brak zalogowanych użytkowników i 4 gości