* * *

Author Topic: Is it possible?  (Read 1431 times)

ci00rix

  • Guest
Is it possible?
« on: August 26, 2005, 12:13:29 pm »
Is it possible to create dynamically allocated tables of objects (classes or structs or something like this)?

The code:

...
Type MyClass = Class
  public
    Arr : Array of String;
end;
...
var Arr2 : array of MyClass;
...
SetLength(Arr2,10);                  
SetLength(Arr2[1].Arr,10);
Arr2[1].Arr[1]:='Hello World!';  // here I got error: sigsegv raised
...

What did I do wrong?

Anonymous

  • Guest
Re: Is it possible?
« Reply #1 on: August 26, 2005, 12:15:05 pm »
Quote from: "ci00rix"
... allocated tables of objects...
Quote

I meant "arrays of objects".

matthijs

  • Hero Member
  • *****
  • Posts: 537
RE: Re: Is it possible?
« Reply #2 on: August 26, 2005, 12:24:17 pm »
Any obejct you want to use, you need to create first. This can be done dynamically of course.
So if you did something like this:
Code: [Select]

var Arr2: array of MyClass;
...
  SetLength(Arr2, 10);
  for I := 0 to 9 do
    Arr2[I] := MyClass.Create;
  SetLength(Arr2[0].Arr, 10);
  Arr2[0].Arr[0] := 'Hello world';
  ...

It might work.
What's in a sig? Would my posting look less if it didnot have a sig? (Free after William S.) :)

:( Why cannot I upload my own Avatar? :(

ci00rix

  • Guest
Is it possible?
« Reply #3 on: August 26, 2005, 12:38:17 pm »
Thanks:)!

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads