Board index » delphi » tfield vs 'fieldbyname'

tfield vs 'fieldbyname'

This is a multi-part message in MIME format.
--------------EA195CE0171E69BF47F20694
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

The on-line help states that although record values can be read and
written using the MyTable.fieldbyname(myfield).asString syntax, creating
a TField object and using MyTField.value is preferable. Why is this
method preferable? (Assuming that I dont need all the properties and
methods available through Tfield). Is this a performance issue? Please
explain in depth, if possible. This is relevant particularly to reading
from large dbf's over a large networks where  maximum performance is
critical.

TIA
MN
--------------EA195CE0171E69BF47F20694
Content-Type: text/x-vcard; charset=us-ascii; name="vcard.vcf"
Content-Transfer-Encoding: 7bit
Content-Description: Card for MN
Content-Disposition: attachment; filename="vcard.vcf"

begin:          vcard
fn:             MN
n:              ;MN
org:            BBU Cutting Inc.
email;internet: M...@bbucutting.com
title:          MIS
x-mozilla-cpt:  ;0
x-mozilla-html: FALSE
end:            vcard

--------------EA195CE0171E69BF47F20694--

 

Re:tfield vs 'fieldbyname'


Yes it is a performance issue. It's better to create persistent fields
and access your table data through the TField descendants components
(TIntegerField, TStringField etc)  instead of using the FieldByName
method. Method FieldByName will try to search the field by looping on
the Fields array of the dataset.

HTH

-------------------------------
Paul Lambadaris
mailto : p...@singular.gr
www    : http://www.singular.gr

Re:tfield vs 'fieldbyname'


It is a performance issue but on of very little consequence.
FieldByName searches the Fields array of the dataset to find the field
object.  This will take a couple of milliseconds which is
inconsequential compared to the time to do the i/o.

Quote
On Thu, 06 Nov 1997 23:41:13 -0500, MN <M...@bbucutting.com> wrote:
>This is a multi-part message in MIME format.
>--------------EA195CE0171E69BF47F20694
>Content-Type: text/plain; charset=us-ascii
>Content-Transfer-Encoding: 7bit

>The on-line help states that although record values can be read and
>written using the MyTable.fieldbyname(myfield).asString syntax, creating
>a TField object and using MyTField.value is preferable. Why is this
>method preferable? (Assuming that I dont need all the properties and
>methods available through Tfield). Is this a performance issue? Please
>explain in depth, if possible. This is relevant particularly to reading
>from large dbf's over a large networks where  maximum performance is
>critical.

>TIA
>MN
>--------------EA195CE0171E69BF47F20694
>Content-Type: text/x-vcard; charset=us-ascii; name="vcard.vcf"
>Content-Transfer-Encoding: 7bit
>Content-Description: Card for MN
>Content-Disposition: attachment; filename="vcard.vcf"

>begin:          vcard
>fn:             MN
>n:              ;MN
>org:            BBU Cutting Inc.
>email;internet: M...@bbucutting.com
>title:          MIS
>x-mozilla-cpt:  ;0
>x-mozilla-html: FALSE
>end:            vcard

>--------------EA195CE0171E69BF47F20694--

Bill

(Sorry but TeamB cannot answer support questions received via email.              )
(To send me email for any other reason remove .nospam from my address.)

Re:tfield vs 'fieldbyname'


Would you tell me how is the difference between the two methods? For
example, when fields are accessed 5000 times in a loop.

Re:tfield vs 'fieldbyname'


Would there also be an advantage to using tfield instead of fieldbyname if
the Actual fieldname changes. For example Say you have a field named
"Customer #' and you decide that you may want to later change the field to
"CustNo" because you may want to convert this app to a C/S app later. If you
use FieldByName throughout your program there would be a lot of search and
replacing but if you used the tfield you could rename the field to match
your existing code. Please comment on this.

Quote
MN wrote in message <34629BE9.F874A...@bbucutting.com>...
>The on-line help states that although record values can be read and
>written using the MyTable.fieldbyname(myfield).asString syntax, creating
>a TField object and using MyTField.value is preferable. Why is this
>method preferable? (Assuming that I dont need all the properties and
>methods available through Tfield). Is this a performance issue? Please
>explain in depth, if possible. This is relevant particularly to reading
>from large dbf's over a large networks where  maximum performance is
>critical.

>TIA
>MN

Re:tfield vs 'fieldbyname'


  I spent the better part of yesterday deleting and readding TFields of
fkData, adjusting SQL inside code and TQueries, and adjusting FieldByName in
code, all due to database restructuring via ERWin.  Oh, also adding indexes
that ERWin forgot about.

  I'm only halfway through, though, because I worked with the project's data
module, and two of the four contractors on this project haven't learned yet
to put their TDatabases, TDataSources and TDataSets on one centralized data
module.

  So you should probably expect to use a mix and match of what's been
discussed.  I usually use persistent TFields, but use FieldByName, for
example, when I want to use a good-looking control like InfoPower's
wwDBLookupCombo, and the rest of the columns of the row use regular Delphi
data-aware controls.

Paul Rice

Quote
Derrick Thomas wrote in message <641158$q...@forums.borland.com>...
>Would there also be an advantage to using tfield instead of fieldbyname if
>the Actual fieldname changes. For example Say you have a field named
>"Customer #' and you decide that you may want to later change the field to
>"CustNo" because you may want to convert this app to a C/S app later. If
you
>use FieldByName throughout your program there would be a lot of search and
>replacing but if you used the tfield you could rename the field to match
>your existing code. Please comment on this.

>MN wrote in message <34629BE9.F874A...@bbucutting.com>...
>>The on-line help states that although record values can be read and
>>written using the MyTable.fieldbyname(myfield).asString syntax, creating
>>a TField object and using MyTField.value is preferable. Why is this
>>method preferable? (Assuming that I dont need all the properties and
>>methods available through Tfield). Is this a performance issue? Please
>>explain in depth, if possible. This is relevant particularly to reading
>>from large dbf's over a large networks where  maximum performance is
>>critical.

>>TIA
>>MN

Re:tfield vs 'fieldbyname'


This is a multi-part message in MIME format.
--------------85A8DD69A23D05CA64E19E3B
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Using  'MyTfield.value' proved to be about 25% faster in a 'fat'
table--over 50 fields and over 17,000 records--the difference increases
exponentially as the number of fields in the table increases.  Of
course, the down side of TField is regarding maintainence, since you've
got to recompile anytime you make any changes to the database.
--------------85A8DD69A23D05CA64E19E3B
Content-Type: text/x-vcard; charset=us-ascii; name="vcard.vcf"
Content-Transfer-Encoding: 7bit
Content-Description: Card for MN
Content-Disposition: attachment; filename="vcard.vcf"

begin:          vcard
fn:             MN
n:              ;MN
org:            BBU Cutting Inc.
email;internet: M...@bbucutting.com
title:          MIS
x-mozilla-cpt:  ;0
x-mozilla-html: FALSE
end:            vcard

--------------85A8DD69A23D05CA64E19E3B--

Re:tfield vs 'fieldbyname'


This is a multi-part message in MIME format.
--------------C76BB8F1E645746E10447C7A
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Thanks for answering!

Quote
> So you should probably expect to use a mix and match of what's been
> discussed.

Yes--what comes out of this is that it's basically a question of the
performance and display properties of TField vs the maintainence hassles
that it entails.
--------------C76BB8F1E645746E10447C7A
Content-Type: text/x-vcard; charset=us-ascii; name="vcard.vcf"
Content-Transfer-Encoding: 7bit
Content-Description: Card for MN
Content-Disposition: attachment; filename="vcard.vcf"

begin:          vcard
fn:             MN
n:              ;MN
org:            BBU Cutting Inc.
email;internet: M...@bbucutting.com
title:          MIS
x-mozilla-cpt:  ;0
x-mozilla-html: FALSE
end:            vcard

--------------C76BB8F1E645746E10447C7A--

Re:tfield vs 'fieldbyname'


Field names should rarely, if ever, change.  However, if that is a
possibility and I wanted to use FieldByName I would define constatnts
for the field names in my Globals unit so I could change them easily.

Bill

(Sorry but TeamB cannot answer support questions received via email.              )
(To send me email for any other reason remove .nospam from my address.)

Other Threads