Welcome, Guest
Guest Settings
Help

Thread: Creating a record at runtime



Permlink Replies: 2 - Last Post: Mar 21, 2017 12:18 AM Last Post By: Roy Lambert Threads: [ Previous | Next ]
Roy Lambert

Posts: 469
Registered: 10/21/99
Creating a record at runtime
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 20, 2017 7:51 AM
To start - I'm using D2006

For a project I'm playing with I want to populate the object property of a TStringlist, but I want to be able to define the data that goes into the objects at runtime. Each item in a given TStringList will have the same data eg this time it might be

integer
int64
string
string
data

next time

integer
string
boolean

The approaches I can come up with are:

1) a TStringList with a separate "header" so I can cast the strings as appropriate (or could be fixed/variable length records as a string)
2) xml
3) json

It feels as though there should be a better way.

Any suggestions?

Roy Lambert

Peter Below

Posts: 1,065
Registered: 12/16/99
Re: Creating a record at runtime
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 20, 2017 12:00 PM   in response to: Roy Lambert in response to: Roy Lambert
Roy Lambert wrote:

To start - I'm using D2006

For a project I'm playing with I want to populate the object property
of a TStringlist, but I want to be able to define the data that goes
into the objects at runtime. Each item in a given TStringList will
have the same data eg this time it might be

integer
int64
string
string
data

next time

integer
stringr
boolean

The approaches I can come up with are:

1) a TStringList with a separate "header" so I can cast the strings
as appropriate (or could be fixed/variable length records as a
string) 2) xml 3) json

It feels as though there should be a better way.

Any suggestions?


I'm not sure I understand your goal here, Roy. Any kind of data can be
represented as a string in some way, and you could store a value (cast
to pointer) into the Objects property that identifies the type (e.g. an
enumeration you define, listing the types you need to support).

An alternative would be to use Variants. Those automatically store the
type of the data you assign to them. Instead of a TStringlist you would
use a dynamic array of Variant of the appropriate length.

--
Peter Below
TeamB

Roy Lambert

Posts: 469
Registered: 10/21/99
Re: Creating a record at runtime
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 21, 2017 12:18 AM   in response to: Peter Below in response to: Peter Below
Peter

I'm not sure I understand your goal here, Roy. Any kind of data can be
represented as a string in some way, and you could store a value (cast
to pointer) into the Objects property that identifies the type (e.g. an
enumeration you define, listing the types you need to support).

Its basically to store data for comparison purposes and the data changes a bit by application (eg comparing files on disk to comparing books). I can easily do what I want using a stringlist stored in the object property of a stringlist but it just doesn't seen very elegant.

An alternative would be to use Variants. Those automatically store the
type of the data you assign to them. Instead of a TStringlist you would
use a dynamic array of Variant of the appropriate length.

I don't use variants much at all. I've always considered them very inefficient but I don't know why.

Roy
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02