I didn't mean to blame it on the array specifically...and I do
wonder what other constructs may affect reference-counted objects as
well...however when using an array he offered this code from his Q&A
Website:

type
  TXArray = array of X;

procedure DeleteX(var A: TXArray; const Index: Cardinal);
var
  ALength: Cardinal;
  TailElements: Cardinal;
begin
  ALength := Length(A);
  Assert(ALength > 0);
  Assert(Index < ALength);
  Finalize(A[Index]);
  TailElements := ALength - Index;
  if TailElements > 0 then
    Move(A[Index + 1], A[Index], SizeOf(X) * TailElements);
  Initialize(A[ALength - 1]);
  SetLength(A, ALength - 1);
end;

where X is an ansistring, using Initialize and finalize will clean up the
array so that a copy of the original item is not left behind and it's
reference count is properly handled. 
        BTW...I've been looking seriously into the NY Institute of
Technologies on-line courses over the last couple of days.  They seem to
have a very complete cirriculem for a BS and even a Masters in computer Sci.
do you or anyone know anything about them or their program?  Since I already
have all my basic courses behind me, I should be able to get thru it in
about a year and a half, so if it weren't for the cost I'd have jumped on it
already.  I'm just wondering if the value is really there for me especially
at this rather late date, or if I should simply continue working on my own
by finding the correct books?   

from Robert Meek dba Tangentals Design  CCopyright 2006

"When I examine myself and my methods of thought, I come to the conclusion
that the gift of Fantasy has meant more to me then my talent for absorbing
positive knowledge!"
                                                    Albert Einstein


-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf
Of Jim Burns
Sent: Monday, March 13, 2006 10:51 AM
To: 'Borland's Delphi Discussion List'
Subject: RE: Objects and Lists...addendum -> Strings


>       What I'm glad I finally did get out of my questioning was Rob's
> information on how use within an array inhibits the normal reference
> counting Delphi uses as I never would have considered that 
> and would have
> ended up with some pretty nasty memory leaks that would be 

I'm not sure I follow you here.  I only have one message from Rob on this
thread and he doesn't say anything of this sort.  But I doubt he would have
explained it quite so simply.  I don't agree Robert that "use within an
array inhibits the normal reference counting...."  It's not that "use within
the array" that causes the problem here.  Regardless of how you hang on to
created "things" be they variabled, record, objects, etc. it /is/ possible
to for ref. counted types to break this handling if you don't insure you at
least keep things with typed pointers.  For example, if you wanted an array
of string pointers use pstring not the generic pointer type and the ref.
counting mechanism should remain intact.  In fact, you can even typecast
them, as long as they exist as pstrings you'll be ok.  But in my experience,
if you encounter this problem there is usually an alternative but I wouldn't
place the blame on arrays per se.


Regards,


Jim


------------------------------------------------------------------------
 Jim Burns, <mailto:[EMAIL PROTECTED]>
   Technology Dynamics
   Pearland, Texas  USA 
   281 485-0410 / 281 813-6939

_______________________________________________
Delphi mailing list -> [email protected]
http://www.elists.org/mailman/listinfo/delphi

_______________________________________________
Delphi mailing list -> [email protected]
http://www.elists.org/mailman/listinfo/delphi

Reply via email to