Field data to TStrings

Is it possible to copy all the items in a particular field of a dataset into a TStrings variable, without loading them manually using a loop?

Something like...

> TStrings1 := Dataset1.fielditems('FIELD1');

Instead of...

> for i := 1 to Dataset1.Recordcount do
TSrings1.add(Dataset1.fieldByName('FIELD1'));

Comments

  • : Is it possible to copy all the items in a particular field of a dataset into a TStrings variable, without loading them manually using a loop?
    :
    : Something like...
    :
    : > TStrings1 := Dataset1.fielditems('FIELD1');
    :
    : Instead of...
    :
    : > for i := 1 to Dataset1.Recordcount do
    : TSrings1.add(Dataset1.fieldByName('FIELD1'));
    :
    :
    You can use the TStrings.Text property for this. It will split the string using the line-ending characters #10#13. If you use the CommaText property the string will be split along its spaces, and commas.
    Note: You should use the TStringList instead of TStrings, because TStrings contains abstract methods, which are implemented in descendants.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion