Moving Columns in a DBGrid seems to move the attached DataSet fields

后端 未结 3 1138
野的像风
野的像风 2021-02-19 23:40

I observed something last week that I did not expect, and will describe below. I am curious as to why this happens. Is it something internal to the TDataSet class, an artifact o

3条回答
  •  死守一世寂寞
    2021-02-20 00:21

    Cary I think I've found a solution for this problem. Instead of using VCL wrapper Fields we need to use an internal Fields property of the Recordset COM object.

    Here is how it should be referenced:

    qry.Recordset.Fields.Item[0].Value
    

    Those fields are NOT affected by the behaviour you have described earlier. So we can still refer to the fields by their index.

    Test this out and tell me what was the result. It worked for me.

    Edit:

    Of course it will work only for ADO components, not for the TClientDataSet...

    Edit2:

    Cary I do not know if this is answer for your question, however I've been pushing folks on the embarcadero forums and Wayne Niddery gave me quite detailed answer about all this Fields movement.

    To make a long story short: If you define your columns in TDBGrid explicitly, field indexes are not moving! Have a bit more sense now, hasn't it?

    Read full thread here: https://forums.embarcadero.com/post!reply.jspa?messageID=197287

提交回复
热议问题