BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Null fields not printing correctly

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Databases (ADO)
View previous topic :: View next topic  
Author Message
Andrew Skinner
Guest





PostPosted: Tue Feb 08, 2005 9:57 am    Post subject: Null fields not printing correctly Reply with quote



I've got (D7, Jet OLE/ADO, Access 97 tables) an application which works
correctly (big news in itself).

In order to print out some small tables I'm copying to a richedit with code
like this (don't really want the trouble of a report writer, though it would
be prettier, version 2 perhaps?):

dataset.first
while not dataset.eof do
begin
temp := #0;
temp := temp + datasetFIRSTFIELD.value + #32;
temp := temp + datasetNEXTFIELD.value;
richedit.lines.add(temp);
dataset.next;
{temp and the fields are strings of course}
end;

This works spot on if nextfield isn't null. If it is null the last non-null
value of nextfield is added, until another non null nextfield is
encountered.

I've worked around it by putting #32 in null fields, and since the whole
thing is small this is no big deal.

I assume this is a feature not a bug, with some complex big database reason
for it, which I shall never understand, but intelligent comments are
welcome.

Andrew


Back to top
Mike Shkolnik
Guest





PostPosted: Tue Feb 08, 2005 11:53 am    Post subject: Re: Null fields not printing correctly Reply with quote



Use the datasetFIRSTFIELD.AsString instead datasetFIRSTFIELD.value

--
With best regards, Mike Shkolnik
EMail: [email]mshkolnik (AT) scalabium (DOT) com[/email]
http://www.scalabium.com

"Andrew Skinner" <skinnner (AT) getridofthisbit (DOT) summerfld.demon.co.uk> wrote in
message news:42088d16 (AT) newsgroups (DOT) borland.com...
Quote:
I've got (D7, Jet OLE/ADO, Access 97 tables) an application which works
correctly (big news in itself).

In order to print out some small tables I'm copying to a richedit with
code
like this (don't really want the trouble of a report writer, though it
would
be prettier, version 2 perhaps?):

dataset.first
while not dataset.eof do
begin
temp := #0;
temp := temp + datasetFIRSTFIELD.value + #32;
temp := temp + datasetNEXTFIELD.value;
richedit.lines.add(temp);
dataset.next;
{temp and the fields are strings of course}
end;

This works spot on if nextfield isn't null. If it is null the last
non-null
value of nextfield is added, until another non null nextfield is
encountered.

I've worked around it by putting #32 in null fields, and since the whole
thing is small this is no big deal.

I assume this is a feature not a bug, with some complex big database
reason
for it, which I shall never understand, but intelligent comments are
welcome.

Andrew





Back to top
Andrew Skinner
Guest





PostPosted: Tue Feb 08, 2005 12:16 pm    Post subject: Re: Null fields not printing correctly Reply with quote



Thank you, but why?

It still seems anomalous behviour.

Andrew


Back to top
Patrick
Guest





PostPosted: Tue Feb 08, 2005 1:37 pm    Post subject: Re: Null fields not printing correctly Reply with quote


Quote:
Thank you, but why?
Because AsString returns a String, which will be '' if the underlying value

is null, and the value as a string if not? Because it has the behavior you
want?

Quote:
It still seems anomalous behviour.
Expecting datasetNEXTFIELD.value to have a value when it is null seems

anomalous.

Time for my coffee.



Back to top
Andrew Skinner
Guest





PostPosted: Tue Feb 08, 2005 8:17 pm    Post subject: Re: Null fields not printing correctly Reply with quote

The anomaly is that the value of the previous row is carried forward as if
it were in the new row.

Anyone can do puns on "as string" and "value", the explanation of why is
what interested me.

Andrew


Back to top
Patrick
Guest





PostPosted: Tue Feb 08, 2005 8:44 pm    Post subject: Re: Null fields not printing correctly Reply with quote

Quote:
The anomaly is that the value of the previous row is carried forward as if
it were in the new row.
Got it. I agree, that is odd--I for sure don't know if it is a bug or by

design.

Quote:
Anyone can do puns on "as string" and "value", the explanation of why is
what interested me.
I guess I mistook what your goal was; certainly replacing .Value with

..AsString is a better 'work around' than filling null fields with a space,
as it does not change your data.



Back to top
Andrew Skinner
Guest





PostPosted: Tue Feb 08, 2005 8:47 pm    Post subject: Re: Null fields not printing correctly Reply with quote

I will, of course, rewrite with .asstring, though the work around works well
enough in the four tables with up to a dozen records each.

Andrew


Back to top
Viatcheslav V. Vassiliev
Guest





PostPosted: Tue Feb 08, 2005 10:03 pm    Post subject: Re: Null fields not printing correctly Reply with quote

If I remebmer correctly, change

function TWideStringField.GetAsWideString: WideString;
begin
GetData(@Result, False);
end;

to

function TWideStringField.GetAsWideString: WideString;
begin
Result := '';
GetData(@Result, False);
end;

This code is in DB unit. It seems that Delphi compiler does not always
initialize (or Finalize) Result if it is WideString in function prolog.

or

if not GetData(@Result, False) then Result := '';

//------------------------------------------
Regards,
Vassiliev V. V.
http://www.managed-vcl.com - using .Net objects in Delphi for Win32 +
ADO.Net
http://www.oledbdirect.com - The fastest way to access MS SQL Server,
MS Jet (Access) and Interbase (through OLEDB)

"Andrew Skinner" <skinnner (AT) getridofthisbit (DOT) summerfld.demon.co.uk>
сообщил/сообщила в новостях следующее:
news:42088d16 (AT) newsgroups (DOT) borland.com...
Quote:
I've got (D7, Jet OLE/ADO, Access 97 tables) an application which works
correctly (big news in itself).

In order to print out some small tables I'm copying to a richedit with
code like this (don't really want the trouble of a report writer, though
it would be prettier, version 2 perhaps?):

dataset.first
while not dataset.eof do
begin
temp := #0;
temp := temp + datasetFIRSTFIELD.value + #32;
temp := temp + datasetNEXTFIELD.value;
richedit.lines.add(temp);
dataset.next;
{temp and the fields are strings of course}
end;

This works spot on if nextfield isn't null. If it is null the last
non-null value of nextfield is added, until another non null nextfield is
encountered.

I've worked around it by putting #32 in null fields, and since the whole
thing is small this is no big deal.

I assume this is a feature not a bug, with some complex big database
reason for it, which I shall never understand, but intelligent comments
are welcome.

Andrew




Back to top
Del M
Guest





PostPosted: Tue Feb 08, 2005 10:08 pm    Post subject: Re: Null fields not printing correctly Reply with quote

Andrew,
This is really esoteric but ... if you use the .value method, no recasting
of the data is done. Since null is unknown type, you cant concatenate it
with any other type (#32 included), so that is why you need to have
"asstring". Remeber Delphi is a "strictly typed" language, unlike VB which
is more like a kitchen appliance not a real programming language. Null is
not empty, blank, space, vapordata or the like, it is "unknown
type/value/neverbeenanything"


Back to top
John Herbster
Guest





PostPosted: Tue Feb 08, 2005 11:32 pm    Post subject: Re: Null fields not printing correctly Reply with quote


"Andrew Skinner" wrote
Quote:
... on "as string" and "value", the explanation of why is
what interested me.

Andrew, Do you have the source code defining the
AsString and Value available?
If so, I suggest studying it. Regards, JohnH

Back to top
Andrew Skinner
Guest





PostPosted: Fri Feb 11, 2005 9:44 am    Post subject: Re: Null fields not printing correctly Reply with quote

Thanks to everyone. Asstring makes it work.

Quote:
This is really esoteric but ... if you use the .value method, no
recasting
of the data is done. Since null is unknown type, you cant concatenate it
with any other type (#32 included), so that is why you need to have
"asstring". Remeber Delphi is a "strictly typed" language, unlike VB which
is more like a kitchen appliance not a real programming language. Null is
not empty, blank, space, vapordata or the like, it is "unknown
type/value/neverbeenanything"

I can sort of see what you are driving at, but the problem was not that the
concatenation failed, but that if the field was null the value in the prior
row was used rather than being discarded.
I can almost see what you are saying, and thanks, I think I follow it.

Anyhow, it works, and I'll stop the lazy use of .value, since usually it
isn't needed, one can use the real type.

Are not variants at variance with a strongly typed language? They were a
fairly late addition to Object Pascal were they not?

<G>

Andrew



Back to top
Del M
Guest





PostPosted: Sat Feb 12, 2005 1:03 pm    Post subject: Re: Null fields not printing correctly Reply with quote

Yes, variants are not strongly typed. I think they were put there for VB
programmers who were trying to learn to use a "real" programming language
<g>


Back to top
Bill Todd
Guest





PostPosted: Sat Feb 12, 2005 3:09 pm    Post subject: Re: Null fields not printing correctly Reply with quote

More likely because they are used extensively in COM. :)

--
Bill Todd (TeamB)
TeamB cannot answer questions received via email

Del M wrote:

Quote:
I think they were put there for VB
programmers who were trying to learn to use a "real" programming language
g

Back to top
Del M
Guest





PostPosted: Sat Feb 12, 2005 7:11 pm    Post subject: Re: Null fields not printing correctly Reply with quote

I know, but I cant pass up a chance to snipe at VB .. and of course we all
know were COM was invented.. :-)


Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Databases (ADO) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.