如何从数组列表中检索包含多维数组的多维类元素

发布于 2024-08-06 09:20:24 字数 1096 浏览 3 评论 0原文

我目前正在 Vista 下使用 CodeGear Delphi 2007。 我的应用程序在一些相当繁重的计算期间返回内存不足错误。 .exe 文件从 150 Mb 增长到惊人的 2 Gb(!哈哈)

关于这个问题:

1)我正在将一些数组更改为 arraylist 但这给了我一些相当困难的问题来解决(参见下面的示例)

2)使用多维结构并需要对代码进行少量更改的建议非常受欢迎!

现在,对成员进行寻址的旧方法是:

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

还有 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; 

在这里,我正在尝试使用新的数组列表来解决问题,但到目前为止还不是很成功

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

不羁少年 2024-08-13 09:20:25

据我所知,ArrayList 是一个 Java/C# 集合,Delphi 中未使用。我们的等效项称为 TObjectList。 (或者 TList,但如果您正在使用对象,最好使用 TObjectList。)您正在使用的是这个吗?我假设你是。

看来您的问题与对象类型有关。有两种方法可以从列表中获取具有正确类型的对象。您可以使用普通列表并对其进行类型转换,或者如果您有 D2009 或 D2010,则可以使用通用列表。

第一种方法,使用 TObjectList:

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

第二种方法:将 ListTriangleRes 声明为 TObjectList,并将 Generics.Collections 添加到 uses 子句中。这为您提供了编译时而不是运行时的类型安全性,因为编译器将确保只有 TTriangleRes 对象进入和离开列表。

无论哪种方式,都不需要中间 TObject 变量。

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.

迷离° 2024-08-13 09:20:25

我不太确定您要做什么,但您的最后一个代码不应该是 MyTriangleRes :=ListTriangleRes[TriangleA-1] ,然后是 Result:=MyTriangleRes.GetVz(ComNr,PtNr) 吗?

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) ?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文