views:

112

answers:

2

Hi,

I'm currently working with CodeGear Delphi 2007 under Vista. My application returns out of memory error during some rather heavy calculations. The .exe files grows from 150 Mb to an amazing 2 Gb (! LOL )

Regarding this issue:

1) I'm changing some arrays into arraylist BUT It's giving me some rather difficult issues to resolve (see sample below)

2) Suggestions that work with multidimensional structures AND require Little changes in the code are MOST appreciated!

Now the old way of addressing a member was:

function TResults.GetTriangleA(ComNr, triangleA, PtNr : integer) : single;
  Begin
  try
    result := ListTriangleRes[TriangleA - 1].GetA(ComNr, PtNr);

And ther's the class TriangleResult:

TTriangleRes = class(TResults)
private
IndexPoint1, IndexPoint2, Indexpoint3 : integer; 
MyA : array of array [1..3] of single;  
MyB : array of array [1..3] of single;

Here, I'm trying to work my way out with the new arraylist, but not very successful till now

function TResults.GetTriangleVz(ComNr, triangleA, PtNr : integer) : single;
Var
  MyTriangleRes:    TTriangleRes;
  MyObj:            Tobject;
begin
  MyTriangleRes:=  TTriangleRes.Create ;
  try
    MyObj := ListTriangleRes[TriangleA - 1] ;
    result := MyObj <<<<?????? how to>>>>MyTriangleRes.GetVz(ComNr, PtNr);

Mkr

Edward

A: 

I'm not really sure what you are trying to do, but shouldn't your last code be MyTriangleRes :=ListTriangleRes[TriangleA-1], and then Result:=MyTriangleRes.GetVz(ComNr,PtNr) ?

Lars D
+1  A: 

As far as I know, ArrayList is a Java/C# collection that's not used in Delphi. Our equivalent is called TObjectList. (Or TList, but it's better to use TObjectList if you're working with objects.) Is that what you're using? I'll assume you are.

It looks like your problem is with the object types. There are two ways to get an object out of a list with the right type. You can use a normal list and typecast it, or if you have D2009 or D2010, you can use a generic list.

First way, using a TObjectList:

MyTriangleRes := ListTriangleRes[TriangleA - 1] as TTriangleRes; //type-safe cast

Second way: Declare ListTriangleRes as a TObjectList<TTriangleRes>, and add Generics.Collections to your uses clause. This gives you type safety at compile time instead of runtime, as the compiler will make sure only TTriangleRes objects go into and come out of the list.

Either way, the intermediate TObject variable isn't needed.

Mason Wheeler
The second way is only available on D2009+, Edward is using D2007
Gerry