Board index » delphi » Begginer question on TFields

Begginer question on TFields

I'm a (ex) Clipper programmer beggining on Delphi (As you maybe could
have seen from my past questions).

My questions are:
1.  I can access a field at runtime with something like this:
    TableName.FieldByName('MyField')
    or
    TableName['MyField']

    Is there any difference?

 

Re:Begginer question on TFields


Quote
Tierra Frtil S.A. wrote:

> I'm a (ex) Clipper programmer beggining on Delphi (As you maybe could
> have seen from my past questions).

> My questions are:
> 1.  I can access a field at runtime with something like this:
>     TableName.FieldByName('MyField')
>     or
>     TableName['MyField']

>     Is there any difference?

Hi.
The first method return TField component and then you can use AsString,
AsInteger and other properties get the value of field.

When you call TableName['MyField'] - you use the index property of
DataSet component which retur the value of field immediatly as variant
type.
I prefer to use the first method, because you can get the exception when
you try to use the second method with NULL value of field, but in other
case the result will be the same, so you can use both these methods.
--
With best regards, Korzh Sergey.
http://korzh.hypermart.net - freeware and shareware programming tools
and Delphi components

Re:Begginer question on TFields


In article <363495FB.BE7D9...@hotmail.com>, Tierra Frtil S.A.
<tfer...@hotmail.com> writes

Quote
>I'm a (ex) Clipper programmer beggining on Delphi (As you maybe could
>have seen from my past questions).

>My questions are:
>1.  I can access a field at runtime with something like this:
>    TableName.FieldByName('MyField')
>    or
>    TableName['MyField']

>    Is there any difference?

It is wierd for us ex-Clipper programmers.  Clipper would have us access
the values with TableName.MyField !

As I (hope that I) understand it...

Tablename[ 'MyField' ] is very slow - because it is a variant.  And cant
be seen with the Tooltip at debug-time.

Tablename.FieldByName( 'MyField' ).AsString (you missed the AsString
out) is better.

But better still is to use the FieldsEditor for Tablename, and add the
field in, so you can use TablenameMyField.Value.  If tablename is in a
datamodule, this has the advantage that you can add 'rules', etc to
MyField.

--
Pete Clark

Give me the strength to change the things I can, the grace to accept the
things I cannot, and a shitload of money.

Replies to pete at elmsoft demon co uk

Other Threads