我想为TStringList.Objects分配一个记录 [英] I want to assign a record to TStringList.Objects
问题描述
我想创建一个播放列表控件。我有很多信息显示在TStringList中。我想为TStringGrid.Objects分配一个记录,而不是一个对象,因为这么多对象可能需要一段时间来创建/销毁。它也需要很多的RAM。
I want create a Playlist control. I have a lot of information to display into a TStringList. I want to assign a record to TStringGrid.Objects instead of an object because so many objects may take a while to create/destroy. It also take a lot of RAM.
记录会更快,更苗条。
我该怎么做?
A record will be much faster and slim. How can I do that?
TYPE
AMyRec= packed record
FullName : string[255];
RelativePath : boolean;
IsInvalid : boolean;
InCache : boolean;
etc
end;
推荐答案
您可以将TList用于记录的指针
You can use a TList to a Pointer of your record.
例如:
Type
PMyrec = ^AMyRec;
使用
var
MyRec : PMyRec;
new(MyRec);
MyRec^.Fullname := 'test';
MyRec^.RelativePath := false;
等
{MyList是一个列表你可以在别处创建其他地方}
{ MyList is a List you have create elsewhere }
MyList.Add(MyRec);
您必须处理列表中的项目,例如
You'll have to handle disposing of items from the list eg
Dispose(PMyRec(MyList [Index]));
要使用项目从列表中:
var
MyRec : PMyRec;
PMyRec := MyList.Items[i];
txtBox.Text = PMyRec^.Fullname;
等
这篇关于我想为TStringList.Objects分配一个记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!