Delphi初学者的问题

a_nobody___ 2017-04-28 03:30:55

就是我想在关闭Form2的同时还要关闭Tabsheet2(,不能引用TTabSheet所在的单元,不以使用消息,不能传递TTabSheet对象)
这个怎么做需要样本。求大神指点------
...全文
180 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
a_nobody___ 2017-05-02
  • 打赏
  • 举报
回复
引用 4 楼 lyhoo163 的回复:
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

{$R *.dfm}

uses Unit1;

procedure TForm2.Button1Click(Sender: TObject);
var VCL:TComponent;
begin
  VCL:=Form1.FindComponent('TabSheet2');
  if VCL <> nil then
    VCL.Free
end;

end.
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ComCtrls;

type
  TForm1 = class(TForm)
    PageControl1: TPageControl;
    TabSheet1: TTabSheet;
    TabSheet2: TTabSheet;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

uses Unit2;

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
  Form2.show;
end;

end.
非常感谢你的指导,我是一个初学者有什么不懂得地方还希望您多多的指导!谢谢
lyhoo163 2017-04-30
  • 打赏
  • 举报
回复


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

{$R *.dfm}

uses Unit1;

procedure TForm2.Button1Click(Sender: TObject);
var VCL:TComponent;
begin
VCL:=Form1.FindComponent('TabSheet2');
if VCL <> nil then
VCL.Free
end;

end.


unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComCtrls;

type
TForm1 = class(TForm)
PageControl1: TPageControl;
TabSheet1: TTabSheet;
TabSheet2: TTabSheet;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

uses Unit2;

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
Form2.show;
end;

end.
a_nobody___ 2017-04-28
  • 打赏
  • 举报
回复
是这样的,用强制转换来做。如果要是能做的出来最好来点样本。
santiaodahan 2017-04-28
  • 打赏
  • 举报
回复
为什么不能引用TTabSheet所在单元,你不告诉对象放在什么地方,又想管理它,这需求有点奇怪。
a_nobody___ 2017-04-28
  • 打赏
  • 举报
回复
是点击Form2中关闭按钮

828

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 非技术区
社区管理员
  • 非技术区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧