Thread View: borland.public.delphi.documentation
2 messages
2 total messages
Started by Nick DeLallo
Sun, 13 Jul 2008 21:09
Creating a Dynamic Array referencing a Class Object
Author: Nick DeLallo
Date: Sun, 13 Jul 2008 21:09
Date: Sun, 13 Jul 2008 21:09
10 lines
1144 bytes
1144 bytes
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
Re: Creating a Dynamic Array referencing a Class Object
Author: 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;
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads