"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Normally the 2 methods are interchangable. However, if the field being returned is empty (i.e. null) then you cannot assign it to a string, as in "s := MyTable['MyField']". You get an exception because you are trying to assign a null variant to a string type.

I.e. using the "MyTable['MyField']" method returns a variant, which can be null. But, using the "MyTable.FieldByName('MyField').AsString" function will always return a string. If the field is null, then the AsString function will return an empty string.

You could do the following, but you will end up typing more code anyway:
if (VarIsNull(MyTable['MyField'])) then
s := ''
else
s := MyTable['MyField'];

Normally, I only use the "MyTable['MyField']" method when assigning a value to the field. When I read a value FROM the field, I use the AsString or AsInteger functions if there's a possibility of the return value being null.

Hope this is what you were looking for.
JB

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.