星期三, 12月 17, 2008

pagecontrol每個tabsheet都是用動態建立的form,節省記憶體

新增一個TPageControl,以及一個TLMDFormDisplay,並將他name命名為fdMainScreen

procedure TForm1.DisplaySimpleForm(ccFormClass:TComponentClass);
begin
try
fdMainScreen.UnLoad();
fdMainScreen.Parent := PageControl1.ActivePage;
fdMainScreen.Execute(TForm(ccFormClass.Create(Application)));
except
exit;
end;

end;

procedure TForm1.PageControl1Change(Sender: TObject);
begin
Screen.Cursor := crHourGlass ;
try
case PageControl1.ActivePageIndex+1 of
1 :
DisplaySimpleForm(TForm2 );
2 :
DisplaySimpleForm(TForm3 );
3 :
fdMainScreen.UnLoad();
end;
finally
Screen.Cursor := crDefault ;
end;
end;

沒有留言: