pagecontrol中关闭创建的tabsheet问题(50分)

  • 主题发起人 主题发起人 seagull007
  • 开始时间 开始时间
...暂时别的没看出问题
下面这句你调用错了,应该是
SendMessage(frmMain.Handle,WM_PCFORMCLOSE,Integer(TForm(self).Parent),Integer(TForm(self)));
我的代码里是写到formclosequery里的sender是form本身,你这里写到了buttonclick事件里,sender就变成了button了,传过去当然就出错了
 
我改了一下试还是不行,如果在主窗体中写代码双击tabsheet标签关闭可以,不会出错,但我想在每个form上用按钮关闭,这样直观些
 
设断点,看看哪句出的错......实在不行.....把你整个工程的文件发邮件给我
 
错都报在delphi源码里,看不懂
 
兄弟,你的邮箱是多少哦,我发给你帮我调一下,谢谢,
 
to hs-kill:兄弟,可以私聊吗,我的QQ是:663535631
 
program Project1;
uses
Forms,
Unit1 in 'Unit1.pas' {Form1},
Unit2 in 'Unit2.pas' {Form2};
{$R *.res}
begin
Application.Initialize;
Application.CreateForm(TForm1, Form1);
Application.Run;
end.

object Form1: TForm1
Left = 192
Top = 88
Width = 689
Height = 523
Caption = 'Form1'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
Visible = True
PixelsPerInch = 96
TextHeight = 13
object PageControl1: TPageControl
Left = 96
Top = 40
Width = 465
Height = 329
TabOrder = 0
end
object Button1: TButton
Left = 280
Top = 392
Width = 75
Height = 25
Caption = '新建'
TabOrder = 1
OnClick = Button1Click
end
end
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComCtrls;
type
TForm1 = class(TForm)
PageControl1: TPageControl;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
public
procedure FreeTabSheet(Sheet: TWinControl);
end;

var
Form1: TForm1;
implementation
uses Unit2;
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
Form2: TForm2;
TabSheet: TTabSheet;
begin
TabSheet := TTabSheet.Create(PageControl1);
TabSheet.PageControl := PageControl1;
Form2 := TForm2.Create(TabSheet);
TabSheet.Caption := Form2.Caption;
Form2.Parent := TabSheet;
Form2.Visible := True;
PageControl1.ActivePage := TabSheet;
end;

procedure TForm1.FreeTabSheet(Sheet: TWinControl);
begin
if PageControl1.ActivePage = Sheet then
if PageControl1.PageCount = 1 then
PageControl1.Visible := False;
Sheet.Free;
end;

end.

object Form2: TForm2
Left = 609
Top = 284
Align = alClient
BorderStyle = bsNone
Caption = 'Form2'
ClientHeight = 155
ClientWidth = 399
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
PixelsPerInch = 96
TextHeight = 13
object Button1: TButton
Left = 24
Top = 24
Width = 75
Height = 25
Caption = '关闭'
TabOrder = 0
OnClick = Button1Click
end
end
unit Unit2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm2 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form2: TForm2;
implementation
uses Unit1;
{$R *.dfm}
procedure TForm2.Button1Click(Sender: TObject);
begin
Form1.FreeTabSheet(Parent);
end;

end.
 
现在上不了QQ.........
 
to e-:我在我的程序里试了不行,要不我把程序发给你帮我调一下
 
hs_kill_god@hotmail.com
 
哦.........找到问题了,你把SendMessage改成PostMessage
sendmessage要等待消息返回......可是返回的时候form已经free了 所以出错.....汗....
 
谢了兄弟,
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
I
回复
0
查看
501
import
I
I
回复
0
查看
560
import
I
后退
顶部