Article View: borland.public.delphi.documentation
Article #46Re: Creating a Dynamic Array referencing a Class Object
From: Warren Postma
Date: Fri, 18 Jul 2008 13:25
Date: Fri, 18 Jul 2008 13:25
26 lines
1752 bytes
1752 bytes
Nick DeLallo wrote:
> I define a dynamic array of Unit2.TestClassExample;
>
> XClassEx : array of Unit2.TclassExample; // okay
> //xClassEx := unit2.TClassExample(self); // does not work
> setlength(xclassEx,100); // okay
>
> // add to the array I get an access error
> // How do I initialize the array.
> // TclassExample is a record containing variable data
>
>
>
Probably TclassExample is not a record, it's a class. You need to
understand the difference between a record and a class.
The main thing to remember about Class types is that declaring one is
not enough, you must also construct it.
var
Foo: Array of TMyClass
begin
SetLength(Foo,10);
/// Foo[0] := TMyClass.Create; // if we don't do this first...
Foo[0].property1 := 10; // ... then we get an Access violation!
end;
Technical Details
Message-ID:
<48809a2b$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!feeder.erje.net!news.isoc.lu!newsgroups.borland.com!not-for-mailReferences:
<487a6f06$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit Date: Fri, 18 Jul 2008 09:25:38 -0400 From: Warren Postma <wp@tekran.com> User-Agent: Thunderbird 2.0.0.14 (Windows/20080421) MIME-Version: 1.0 Newsgroups: borland.public.delphi.documentation Subject: Re: Creating a Dynamic Array referencing a Class Object References: <487a6f06$1@newsgroups.borland.com> In-Reply-To: <487a6f06$1@newsgroups.borland.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 64.214.196.86 Message-ID: <48809a2b$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1216387627 64.214.196.86 (18 Jul 2008 06:27:07 -0700) Lines: 27 Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!feeder.erje.net!news.isoc.lu!newsgroups.borland.com!not-for-mail