In Unit1.h
private:

struct gydytojas {
   int gydid, amzius, specialyb, telefonas, asmkod;
   String vardas[25];
   String pavarde[35];
   String adresas[50]; };
  gydytojas gydmas[100];

Now in Unit1.cpp im trying to do simple thing:

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

gydytojas.vardas=Edit21->Text;
gydytojas.pavarde=Edit22->Text;
gydytojas.adresas=Edit24->Text;
}

Getting these errors:
[C++ Error] Unit1.cpp(172): E2108 Improper use of typedef 'TForm1::gydytojas'
Unit1.cpp(170): parsing: void _fastcall TForm1::Button18Click(TObject *)

Any suggestions ?

Recommended Answers

All 6 Replies

gydytojas is a struct, but you use it like an object. The problem is the same as if you tried to say int.value = 5; , and the fix is to define a variable of gydytojas to work with. :)

commented: Thanks for help ;) +1

gydytojas is a struct, but you use it like an object. The problem is the same as if you tried to say int.value = 5; , and the fix is to define a variable of gydytojas to work with. :)

Oh, so you mean i should define another variable to gydytojas, for example i got : gydytojas gydmas[100]; As if i do so, i get an error:

[C++ Error] Unit1.cpp(169): E2277 Lvalue required
Unit1.cpp(168): parsing: void _fastcall TForm1::Button18Click(TObject *)

And i had changed in struct of gydytojas from String vardas, to AnsiString vardas.

Can you please post the code that causes this error? It looks like you're defining the variable wrong or using it wrong.

Can you please post the code that causes this error? It looks like you're defining the variable wrong or using it wrong.

void __fastcall TForm1::Button18Click(TObject *Sender)
{
gydmas[1].vardas=Edit21->Text;

This is the code for which that error is generated.

And this code is used in Unit1.h

private:	// User declarations

 

  struct gydytojas {
   int gydid, amzius, specialyb, telefonas, asmkod;
   String vardas[25];
   String pavarde[35];
   String adresas[50]; };
  
   gydytojas gydmas[100];

vardas is an array of 25 Strings. So if you want to keep it that way, you need to use
something like: gydmas[1].vardas[[B]some_valid_index_here[/B]] = Edit21->Text;

commented: Thanks for help ;) +1

vardas is an array of 25 Strings. So if you want to keep it that way, you need to use
something like: gydmas[1].vardas[[B]some_valid_index_here[/B]] = Edit21->Text;

Thanks, this problem solved :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.