Re: Problem closing app with big UDT

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Do you have the two declarations (VB and Delphi) to post? Carefully check
the array specs. Note that a VB array specs the highest element number and
the Delphi array specs the total number of elements (zero based). Be sure
you don't have an "off by one" error shifting a boundary somehow.

We're actually converting our VB app (on an opportunistic basis) to Delphi.
Doing it piece by piece means that we rewrite a segment in Delphi and expose
it to the VB front using a DLL. We had a three choices in passing data:

1. Use COM to pass complex types
2. Match calls of complex types on both sides
3. Keep It Simple, passing only basic types (integer, single, double,
pChar).

We're trying to get away from COM, so that was out.

Matching complext types on both sides was going to be a constant (and hard
to diagnose) headache. This is what you're doing and in our experience it's
a royal PITA (BTDT). The problem is that you can't easily get to the
"transfer" code to see what's going on with the mapping.

What we're doing with the last option is to only pass those basic types, but
do our own marshaling of complex types by encoding them into byte arrays.
It takes a little more effort to get started doing this, but once you set up
the process it's not hard. The benefit is that you can easily troubleshoot
the problems because the marshaling is visible without tracing machine code.
That's why I mentioned doing it just passing bytes.

If your Delphi programmer is too busy, why not just crank up a copy and
tinker with it yourself? Free here:

www.turboexplorer.com

It's not that hard for a VB developer. The more Delphi I do the happier I
am with it.

Dan

"David Kerber" <ns_dkerber@xxxxxxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:MPG.1fcd6278db65fb83989a4e@xxxxxxxxxxxxxxxxxxxxxx
In article <u5YSTFcDHHA.3604@xxxxxxxxxxxxxxxxxxxx>, Dan@xxxxxxxx says...
This same structure works with no trouble in
Delphi.

Are you trying to pass the UDT between VB and Delphi, or do you just mean
that the Delphi equivalent works fine?

Passing it back and forth between a Delphi .dll to a VB application.
Yes, we are aware of the alignment issue, and have designed with that in
mind. ALL the data is of one of 3 types: Long, Double, or Byte array.
All the array sizes are multiples of 4, so the 4-byte alignment should
be maintained throughout unless we screwed up somewhere. We didn't
think of passing the whole thing as a byte array, and it's too late to
go back and rework it now.

My gut feeling is that there's something in the .dll that isn't
intializing a small part of the structure correctly; I've got the Delphi
programmer looking at this, because it used to work ok. But I don't
know what (if anything) has changed, so it's tough to isolate.


As JFrench said, if you're passing the data between VB and Delphi you
need
to be sure the alignment matches. Note that there are *more options*
than
just Packed or not Packed ("Project Options|Compiler|Record field
alignment"). Delphi allows you to specify the alignment boundary. You
should also carefully check the data types.

FWIW, I don't pass UDT's as UDT's. I put them in byte arrays for the
pass
so I can't speak from experience on making it work. I think it should be
OK
though..

Dan


"David Kerber" <ns_dkerber@xxxxxxxxxxxxxxxxxxxxxxxxxxxxx> wrote in
message
news:MPG.1fcb718e18e4ad9b989a4a@xxxxxxxxxxxxxxxxxxxxxx
I have an app which uses a big (44708 bytes) UDT, which is made up of
Longs, Doubles and byte arrays. Since that is bigger than 32k, the
compiler chokes on it when I try to define it as a local, and demands
that I dim it as either a global or at the form level before it will
compile.

Once I do that, it runs fine until I shut down the app. When running
in
the IDE, it just silently kills the IDE. When running compiled, it
throws the folloging "Application Error": The instruction at
"0x00000000" referenced memory at "0x00000000". The memory could not
be
"read".

This isn't a show-stopper because the app works fine until I close it
out, but it's rather disconcerting, especially to my users. Any ideas
on how to fix this? This same structure works with no trouble in
Delphi.


--
Remove the ns_ from if replying by e-mail (but keep posts in the
newsgroups if possible).


.



Relevant Pages

  • Re: Problem closing app with big UDT
    ... Are you trying to pass the UDT between VB and Delphi, or do you just mean that the Delphi equivalent works fine? ... All the array sizes are multiples of 4, so the 4-byte alignment should be maintained throughout unless we screwed up somewhere. ... In any one app, maybe, but this dll is in production use in several different apps, in 3 different languages. ... So coming at it from a different direction is there any way I can, just in my VB app, send and receive the structure I need without actually passing it as a structure? ...
    (microsoft.public.vb.general.discussion)
  • Re: Problem closing app with big UDT
    ... Are you trying to pass the UDT between VB and Delphi, ... Passing it back and forth between a Delphi .dll to a VB application. ... ALL the data is of one of 3 types: Long, Double, or Byte array. ... In any one app, maybe, but this dll is in production use in several ...
    (microsoft.public.vb.general.discussion)
  • Re: array of labels or array of buttons
    ... >>finally got a project that I can do in Delphi. ... >>time you cut and past one it asks if you want to make this an array. ... > draw the buttons in an OnDrawCell event handler of the stringgrid like ... ... > In this case I would use the Objects array of the string grid to store a value ...
    (alt.comp.lang.borland-delphi)
  • Re: Freeing a record which contains a string field leads to a memory/string leak ?!
    ... Delphi comes from Pascal, and although Pascal is a strongly typed ... ANSIStrings deliberately hide the memory allocation that is going on, ... AR:Array Of TRec; ... what Delphi is really providing is an Array of 4 byte pointers to ...
    (alt.comp.lang.borland-delphi)
  • Re: Problem closing app with big UDT
    ... Are you trying to pass the UDT between VB and Delphi, ... Passing it back and forth between a Delphi .dll to a VB application. ... ALL the data is of one of 3 types: Long, Double, or Byte array. ... All the array sizes are multiples of 4, so the 4-byte alignment should ...
    (microsoft.public.vb.general.discussion)