How can I access a TDBGrid column by name instead of by Index?
<p>How can I access a TDBGrid column by name instead of Index?</p>

<p>For example, now I use:</p>

<pre><code> grdInvoiceItems.Columns[2].Visible := False;
</code></pre>

<p>but it would be much better to write something like:</p>

<pre><code> grdInvoiceItems.Columns['UnitPrice'].Visible := False;
</code></pre>

<p>In the mean time I use a for cycle like in:</p>

<pre><code>  for idx := 0 to grdInvoiceItems.Columns.Count - 1 do
    begin
    if (
         (grdInvoiceItems.Columns[idx].FieldName = 'UnitPrice') or
         (grdInvoiceItems.Columns[idx].FieldName = 'Discount') or
         (grdInvoiceItems.Columns[idx].FieldName = 'SecretCode')
       ) then
      grdInvoiceItems.Columns[idx].Visible := False;
    end;
</code></pre>

<p>Using colum name is IMO much better tham column index since index is subject to change more often than name.</p>

<p>Any idea on how to encapsulate it better?</p>