TStringList AddObject

In a C++Builder project, I want to store names of people together with a floating point number for each of them. I tried to write TFloatNum, a simple class for storing a float. Later on in the code I use that class.
The compiler gives an error about the line with AddObject: E2188 Expression syntax

I guess something is wrong with the TFloatNum class, because when I write the following, it compiles without errors:
StringList1->AddObject("John Jones", Button1);
What am I doing wrong?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
class TFloatNum {
  private:
    float FNum;
    void SetNum(float x) { FNum = x; };
  public:
    __property float Num = { read = FNum, write = FNum };
};

void __fastcall TForm1::btnAddClick(TObject *Sender)
{
  TFloatNum *G = new TFloatNum;
  G->Num = 75.5;
  StringList1->AddObject("John Jones", G*);
}
Last edited on
I'm not familiar with C++Builder, but have you tried *G instead of G*? G* is definitely not normal C++.
Thanks for looking into this.
When I try: StringList1->AddObject("John Jones", *G);
it gives two errors:
E2034 Cannot convert TFloatNum to TObject*
E2342 Type mismatch in parameter AObject (wanted TObject*, got TFloatNum)
Topic archived. No new replies allowed.