用TLIST的ADDOBJECT方法可以实现;
TheArray:array of Tform;
function ReturnYourWant(tmp:TheArray):TheArray;
var TmpList:TList;
i:integer;
begin
TmpList:=TList.Create;
for i:=0 to High(TheArray) do
TmpList[i].addobject(TheArray[i]);
//删除TmpList中不要的,自动排序了已经
//然后再循环复制给函数返回就可以了
end;
TheArray:array of Tform;
function ReturnYourWant(tmp:TheArray):TheArray;
var TmpList:TList;
i:integer;
begin
TmpList:=TList.Create;
for i:=0 to High(TheArray) do
TmpList[i].addobject(TheArray[i]);
//删除TmpList中不要的,自动排序了已经
//然后再循环复制给函数返回就可以了
end;
var
a: TStrings;
i: Integer;a := TStringList.Create;
for i := Low(curFormArr) to High(curFormArr) do
if curFormArr[i] <> '' then
a.Add(curFormArr[i]);
SetLength(curFormArr, a.Count);
for i := 0 to a.Count - 1 do
curFormArr[i] := a[i];
a.Free;
var
i:integer;
begin
for i:=index-1 to High(arytemp)-2 do
TForm(aryTemp[i]).Assign(aryTemp[i+1]);
//////把指定位置后面的元素前移。
TForm(aryTemp[High(aryTemp)-1]).Free;
///////删除最后一个元素
end;
myFormList:=Tlist.Create; FormHaveCreate:=false;
toShowIndex:=-1;
toDelIndex:=-1;
{1.找有无记入List}
for i:=0 to myFormList.Count-1 do
begin
if uppercase(TForm(myFormList.items[i]).Name)= uppercase(to_FormName) then
begin // showmessage('找到');
FormHaveCreate:=true;
toShowIndex:=i;
Break;
end;
end; {2.将<>toshowindex 的都Close}
for i:=0 to myFormList.Count-1 do
if i<>toShowIndex then
TForm(myFormList.Items[i]).Close; {3.找有无要删除出myFormList的:因所有Form都是无模式表单,我在个别的表单的onclose 事件中加入 Active:=cnFree 语句,目的是在执行close时从内存中释放它,下面的for块目的就是找出要删除的索引号}
for i:=0 to myFormList.Count-1 do
begin
//showmessage(Trim(TForm(myFormList.Items[i]).Name));
{奇就奇在这里,执行有上面这句(或其它showmessage语句“中断一下”,程序运行如愿,没有的话就不能进入下面这句判断语句中,不能修改toDelIndex的值}
tmpName:= Trim(TForm(myFormList.Items[i]).Name);
if Trim(TForm(myFormList.Items[i]).Name)='' then
begin
showmessage('找到要删除的');
toDelIndex:=i;
end;
end;
{4.建立}
if not FormHaveCreate then
toShowIndex:=myFormList.Add(myCreatMBForms(tocreate,to_FormMG)); {5.显示}
TForm(myFormList.Items[toShowIndex]).Parent:=frmMain.Panel1;
TForm(myFormList.Items[toShowIndex]).Show;
{6.删除}
showmessage(' todel '+inttostr(todelindex));
if toDelIndex<>-1 then
begin
// TForm(myFormList.Items[toDelIndex]).Free;
myFormList.Items[toDelIndex]:=nil;
myFormList.Delete(toDelIndex);
end;
望高手们为我解决,谢谢了!
for i:=0 to myFormList.Count-1 do
begin
//showmessage(Trim(TForm(myFormList.Items[i]).Name));
{奇就奇在这里,执行有上面这句(或其它showmessage语句“中断一下”,程序运行如愿,没有的话就不能进入下面这句判断语句中,不能修改toDelIndex的值}
tmpName:= Trim(TForm(myFormList.Items[i]).Name);
//这里TMPNAME的值是多少?另外下面的判断直接就用TMPNAME吧。
if Trim(TForm(myFormList.Items[i]).Name)='' then
begin
showmessage('找到要删除的');
toDelIndex:=i;
end;
begin
showmessage('找到要删除的');
toDelIndex:=i;
end;
真奇!
特别是用system.move可以直接对内存进行操作另,若要用TList进行添加元素,最好先设定其Capicity属性,以提高效率