我只写一个主窗体,4个拿来测试的form,别的什么代码都没有,
这是主窗体代码:
unit Main;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Menus, jpeg, ExtCtrls, RzTabs, RzPanel;
const
WM_PCFORMCLOSE = WM_USER + 100;
type
TfrmMain = class(TForm)
MainMenu1: TMainMenu;
N1: TMenuItem;
N2: TMenuItem;
N3: TMenuItem;
N4: TMenuItem;
N5: TMenuItem;
RzPanel1: TRzPanel;
Image1: TImage;
RpgcMain: TRzPageControl;
sdfsdf1: TMenuItem;
procedure FormShow(Sender: TObject);
procedure N2Click(Sender: TObject);
procedure N3Click(Sender: TObject);
procedure N5Click(Sender: TObject);
procedure sdfsdf1Click(Sender: TObject);
private
{ Private declarations }
tabsheet : TRzTabSheet;
stabsheetname : String;
pagecontrolindex : Integer;
Function getPageControlSheetName(str:String):Boolean;
procedure CreateTabSheet(myFormClass: TFormClass;var Reference: TForm);
procedure AddTabSheet(tabname:String;myFormClass: TFormClass;var Reference: TForm);
procedure pagecontrolVisible;
public
{ Public declarations }
procedure FreePageControl;
procedure PCFormClose(var msg:TMessage);
message WM_PCFORMCLOSE;
end;
var
frmMain: TfrmMain;
activepagecontronindex : Integer;
//当前的index
implementation
uses cgrk, cgjh, Unit1, Unit2;
{$R *.dfm}
procedure TfrmMain.CreateTabSheet(myFormClass: TFormClass;var Reference: TForm);
var
MyForm : TForm;
begin
tabsheet := TRzTabSheet.Create(Nil);
tabsheet.Caption := Reference.Caption;
tabsheet.PageControl := RpgcMain;
tabsheet.Name := stabsheetname;
MyForm := myFormClass.Create(tabsheet);
MyForm.Parent := tabsheet;
MyForm.BorderStyle := bsnone;
MyForm.Align := alClient;
RpgcMain.ActivePage := tabsheet;
MyForm.Show;
end;
procedure TfrmMain.FormShow(Sender: TObject);
begin
Self.RpgcMain.Visible := False;
end;
procedure TfrmMain.FreePageControl;
var
ncount : Integer;
begin
ncount := Self.RpgcMain.PageCount;
if ncount > 0 then
begin
Self.RpgcMain.ActivePage.Free;
if ncount > 1 then
Self.RpgcMain.ActivePageIndex := ncount - 2
else
Self.RpgcMain.Visible := False;
end;
end;
function TfrmMain.getPageControlSheetName(str: String): Boolean;
var
i : Integer;
strName : String;
begin
Result := False;
For i := 0 to (Self.RpgcMain.PageCount - 1)do
begin
strName := Trim(Self.RpgcMain.Pages.Name);
pagecontrolindex := Self.RpgcMain.Pages.PageIndex;
if strName = Trim(str) then
//该名称已存在
begin
Result := True;
Break;
end;
end;
end;
procedure TfrmMain.N2Click(Sender: TObject);
begin
stabsheetname := 'tabsheetN2';
Self.AddTabSheet(stabsheetname,Tfrmcgrk,TForm(frmcgrk));
end;
procedure TfrmMain.N3Click(Sender: TObject);
begin
stabsheetname := 'tabsheetN3';
Self.AddTabSheet(stabsheetname,Tfrmcgjh,TForm(frmcgjh));
end;
procedure TfrmMain.pagecontrolVisible;
begin
if RpgcMain.Visible = false then
RpgcMain.Visible := true;
end;
procedure TfrmMain.N5Click(Sender: TObject);
begin
stabsheetname := 'tabsheetN5';
Self.AddTabSheet(stabsheetname,TForm1,TForm(Form1));
end;
procedure TfrmMain.sdfsdf1Click(Sender: TObject);
begin
stabsheetname := 'tabsheetsdfsdf1';
Self.AddTabSheet(stabsheetname,TForm2,TForm(Form2));
end;
procedure TfrmMain.AddTabSheet(tabname:String;myFormClass: TFormClass;
var Reference: TForm);
begin
if Self.getPageControlSheetName(tabname) then
//已经存在
begin
RpgcMain.ActivePageIndex := pagecontrolindex;
//显示出来
Self.pagecontrolVisible;
end
else
//创建
begin
Self.CreateTabSheet(myFormClass,Reference);
Self.pagecontrolVisible;
end;
end;
procedure TfrmMain.PCFormClose(var msg: TMessage);
begin
TForm(msg.LParam).Free;
TRzTabSheet(msg.WParam).Free;
end;
end.
这是每个form中关闭按钮的代码,别的什么代码也没有;
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Label1: TLabel;
Edit1: TEdit;
Edit2: TEdit;
Button1: TButton;
Button2: TButton;
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
uses Main;
{$R *.dfm}
procedure TForm1.Button2Click(Sender: TObject);
begin
showmessage(inttostr(frmMain.RpgcMain.ActivePageIndex));
SendMessage(frmMain.Handle,WM_PCFORMCLOSE,Integer(TForm(Sender).Parent),Integer(TForm(Sender)));
end;
end.
兄弟帮我看看是什么问题哦,今天搞不定就不想弄了,放几天再说