Board index » delphi » Accessing record structures with a string.

Accessing record structures with a string.

Is there a better way of achieving the following?

I have a Pagecontrol with multiple tabsheets  showing checkboxes and spin
buttons.
In the program is a record structure containing data on several clients.
ClientA, ClientB, ClientC etc.
Captions on the tabsheets are ClientA, ClientB, ClientC etc.

I would like to use the page control changing event to enter data into the
recordstructure.

The record structure is this.
TClient = Record
ClientAPrintOn:Boolean;
ClientAPrintNo:Integer;
ClientBPrintOn:Boolean;
ClientBPrintNo:Integer;
ClientCPrintOn:Boolean;
ClientCPrintNo:Integer; ...

Is there a means of using the captions of the tabsheets to access the
members of the record. I tried creating a string to do this but kept getting
a undeclared identifier error.
This is what I tried.
Var:
TempString:String;

TempString := PageControl1.TTabSHeet.caption + 'PrintOn'
ShowMessage (TempString) gives a message box with ClientAPrintOn

However
Client.(TempString) := Checkbox1.Checked; gives the error.

Have I got the syntax wrong, is there a better way of achieving this?

Thank you in anticipation.

 

Re:Accessing record structures with a string.


<<Iain L. Grant:
Client.(TempString) := Checkbox1.Checked; gives the error.

Have I got the syntax wrong,

Quote

You can't access a record like that, you need to put the
name of the relevant part at compile time. There are
various things you might do, e.g. make your record
  TClient = Record
    Client: string;
    ClientPrintOn: Boolean;
    ClientPrintNo: Integer;
  end;
- it's hard to know what would be best without knowing more
about what you're trying to do.

However, this is completely the wrong newsgroup -
objectpascal would be better. :)

--
Deborah Pate (TeamB) http://delphi-jedi.org

  Use Borland servers; TeamB don't see posts via ISPs
  http://www.borland.com/newsgroups/genl_faqs.html

Other Threads