Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Creating a Dynamic Array referencing a Class Object

0 views
Skip to first unread message

Nick DeLallo

unread,
Jul 13, 2008, 5:09:26 PM7/13/08
to

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

Warren Postma

unread,
Jul 18, 2008, 9:25:38 AM7/18/08
to
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;

0 new messages