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 

object reference not set every other time

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






PostPosted: Fri Jul 14, 2006 5:51 am    Post subject: object reference not set every other time Reply with quote



Anyone know why I might get an "Object reference not set to an instance of
an object" error every *other* time I open a ClientDataSet?

Here's my environment:

Windows XP Pro
Delphi 2005 w/ Update 3
SQL Server 2000
dbExpress

I'm about 2/3 through a conversion project from an old Delphi/BDE=>dBASE
program that I'm upgrading to Delphi 2005 for .NET (using the VCL.NET for
most of it). I've chosen dbExpress to talk to the new SQL Server database
and have several data modules with a mix of straight queries and stored
procedures that bring back result sets. I've got grids hooked up to
ClientDataSets with updates going back to the server and many other things
that are working fine.

But one small screen of information is driving me crazy. It has a page
control with the first page containing a very simple grid of records. When
you switch to the second page, it takes the ID of the record you're on in
the first page, sets a parameter to a ClientDataSet and opens it returning
the set of records for that particular row in the first page. When you
switch back to the first page, the dataset for the second page is closed.

The first time I switch to the second page, it works just fine. I see the
records associated with the first page's highlighted record. So I switch
back to the first page and select a different row, then switch back to the
second page. But when the dataset tries to open the second time, I get the
error, "Object reference not set to an instance of an object" and the
resulting grid is blank. However, if I switch back to the first page and
back again to the second page (either on the same first page's record or a
different one), the grid of data opens just fine. Every other time, I get
the error.

The dataset on the second page is coming from a stored procedure that pulls
data from two tables. (The ClientDataSet's DataSetProvider has an
OnGetTableName event to specify the table name that should be updated. The
ClientDataSet has both AfterDelete and AfterPost pointing to an event
handler that calls ApplyUpdates.)

I would GREATLY appreciate any clues to help me get rid of that error.


Thanks!

--
David Cornelius
http://corneliusconcepts.com
Back to top
Craig Stuntz [TeamB]
Guest





PostPosted: Fri Jul 14, 2006 5:42 pm    Post subject: Re: object reference not set every other time Reply with quote



<dev (AT) corneliusconcepts (DOT) com> wrote:

Quote:
Anyone know why I might get an "Object reference not set to an
instance of an object" error every other time I open a ClientDataSet?

What's the call stack? Use debug DCUs when you check.

--
Craig Stuntz [TeamB] · Vertex Systems Corp. · Columbus, OH
Delphi/InterBase Weblog : http://blogs.teamb.com/craigstuntz
Want to help make Delphi and InterBase better? Use QC!
http://qc.borland.com -- Vote for important issues
Back to top
David Cornelius
Guest





PostPosted: Fri Jul 14, 2006 8:48 pm    Post subject: Re: object reference not set every other time Reply with quote



The list is long, so I hope you don't mind a screen shot, since there
doesn't appear to be any easy way to export the call stack to text. I
uploaded it to b.p.attachments under the same subject.

The only lines missing at the bottom are:
Borland.Vcl.TApplication::ProcessMessages()
Borland.Vcl.TApplication::HandleMessage()
Borland.Vcl.TApplication::Run()
RD.Units.RD::RD()


Thanks,

David.


"Craig Stuntz [TeamB]" <craig_stuntz (AT) nospam (DOT) please [a.k.a. acm.org]> wrote
in message news:44b79136 (AT) newsgroups (DOT) borland.com...
Quote:
dev (AT) corneliusconcepts (DOT) com> wrote:

Anyone know why I might get an "Object reference not set to an
instance of an object" error every other time I open a ClientDataSet?

What's the call stack? Use debug DCUs when you check.

--
Craig Stuntz [TeamB] · Vertex Systems Corp. · Columbus, OH
Delphi/InterBase Weblog : http://blogs.teamb.com/craigstuntz
Want to help make Delphi and InterBase better? Use QC!
http://qc.borland.com -- Vote for important issues
Back to top
Craig Stuntz [TeamB]
Guest





PostPosted: Fri Jul 14, 2006 9:23 pm    Post subject: Re: object reference not set every other time Reply with quote

It doesn't look to me like the CDS has anything to do with it, based
on your stack. You should be able to build a simple test app which
simply opens the CDS and does nothing else to verify this. I think
you're seeing a side effect of something else your app is doing.

The stack isn't hugely informative, but does tell you that the issue
is in message passing. That probably points to a visual component, or
an event in a visual component.

You need to narrow down what is actually causing the problem. Try
commenting out the code which opens the CDS. Try disconnecting the
grid, but letting the CDS open. Etc.

--
Craig Stuntz [TeamB] · Vertex Systems Corp. · Columbus, OH
Delphi/InterBase Weblog : http://blogs.teamb.com/craigstuntz
IB 6 versions prior to 6.0.1.6 are pre-release and may corrupt
your DBs! Open Edition users, get 6.0.1.6 from http://mers.com
Back to top
David Cornelius
Guest





PostPosted: Fri Jul 14, 2006 10:07 pm    Post subject: Re: object reference not set every other time Reply with quote

Yeah, I'm sure this is a side-effect somewhere, but I can't imagine where.
I've commented out the "open" and the problem does not appear (rules out
page switching on the form). The grid's only event is a double-click event.
The data source does not have any events. The CDS has only trapped
AfterDelete and AfterPost (both simply calling ApplyUpdates). The
DataSetProvider simply returns the table name in OnGetTableName.

The TSQLDataSet opens a stored procedure which returns a result set. I
looked at the stored procedure some more and realized it's fairly simple, so
just copied it to the Delphi component, switched it to ctQuery, renamed the
parameter, and ran it again.

Voila! No more errors!!!

So, when I use stored procedures to return result sets (I do in a couple
other places with no problems), there must be some trick I missed here that
I inadvertently got right elsewhere.

Oh well, I think I'll leave it as is and move on!

Thanks for your feedback,

David.
Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Databases (dbExpress) 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.