几个小问题,请指教! ( 积分: 6 )

  • 主题发起人 主题发起人 del_today
  • 开始时间 开始时间
D

del_today

Unregistered / Unconfirmed
GUEST, unregistred user!
请教各路高手:

以下为一个克隆程序的全部代码,就此想问几个问题,请指教!谢谢!

问题1:
语句TFormClass(Self.ClassType)中,TFormClass()是什么意思? Self.ClassType又是什么意思?

问题2:
语句with TControlClass (Sender.ClassType).Create (self) do中,
TControlClass ()是何意? Sender.ClassType又是何意?
这两个问题怎么在Delphi自身的help里,也查不到答案呀?请高手帮忙!

问题3:
语句Sender as TControl是什么意思?和with语句有关吗?

问题4:
Parent在这个程序中是什么意思?


//************************************


unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Buttons;

type
TForm1 = class(TForm)
Button1: TButton;
ScrollBox1: TScrollBox;
Label1: TLabel;
CheckBox1: TCheckBox;
Label2: TLabel;
Button2: TButton;
Edit1: TEdit;
BitBtn1: TBitBtn;
SpeedButton1: TSpeedButton;
GroupBox1: TGroupBox;
RadioButton1: TRadioButton;
RadioButton2: TRadioButton;
procedure Button1Click(Sender: TObject);
procedure ClickComp(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
var
AForm: TForm;
begin
// clone the 'self' object
Application.CreateForm (
TFormClass(Self.ClassType), AForm);
// move the form and show it
AForm.Left := Left + 50;
AForm.Top := Top + 50;
AForm.Show;
end;

procedure TForm1.ClickComp(Sender: TObject);
var
ControlText: string;
begin
with TControlClass (Sender.ClassType).Create (self) do
begin
Parent := (Sender as TControl).Parent;
Left := (Sender as TControl).Left + 10;
Top := (Sender as TControl).Top + 10;
SetLength (ControlText, 50);
(Sender as TControl).GetTextBuf(
PChar(ControlText), 50);
ControlText := PChar(ControlText) + ' *';
SetTextBuf (PChar (ControlText));
end;
end;

end.
 
请教各路高手:

以下为一个克隆程序的全部代码,就此想问几个问题,请指教!谢谢!

问题1:
语句TFormClass(Self.ClassType)中,TFormClass()是什么意思? Self.ClassType又是什么意思?

问题2:
语句with TControlClass (Sender.ClassType).Create (self) do中,
TControlClass ()是何意? Sender.ClassType又是何意?
这两个问题怎么在Delphi自身的help里,也查不到答案呀?请高手帮忙!

问题3:
语句Sender as TControl是什么意思?和with语句有关吗?

问题4:
Parent在这个程序中是什么意思?


//************************************


unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Buttons;

type
TForm1 = class(TForm)
Button1: TButton;
ScrollBox1: TScrollBox;
Label1: TLabel;
CheckBox1: TCheckBox;
Label2: TLabel;
Button2: TButton;
Edit1: TEdit;
BitBtn1: TBitBtn;
SpeedButton1: TSpeedButton;
GroupBox1: TGroupBox;
RadioButton1: TRadioButton;
RadioButton2: TRadioButton;
procedure Button1Click(Sender: TObject);
procedure ClickComp(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
var
AForm: TForm;
begin
// clone the 'self' object
Application.CreateForm (
TFormClass(Self.ClassType), AForm);
// move the form and show it
AForm.Left := Left + 50;
AForm.Top := Top + 50;
AForm.Show;
end;

procedure TForm1.ClickComp(Sender: TObject);
var
ControlText: string;
begin
with TControlClass (Sender.ClassType).Create (self) do
begin
Parent := (Sender as TControl).Parent;
Left := (Sender as TControl).Left + 10;
Top := (Sender as TControl).Top + 10;
SetLength (ControlText, 50);
(Sender as TControl).GetTextBuf(
PChar(ControlText), 50);
ControlText := PChar(ControlText) + ' *';
SetTextBuf (PChar (ControlText));
end;
end;

end.
 
语句TFormClass(Self.ClassType)中,TFormClass就是指你所创建的类.Self.ClassType,
Self是一个内建的变量.它就是Tformclass的别名.通过它可以寻址操作该方法所属的对象.

TControlClass在帮助可以~
Control:Represents the base class for all controls that are visible at runtime. TControl is the common ancestor of all visual components and provides standard visual controls like position and cursor. This class also provides events that respond to mouse actions.
sender是用来指出哪个组件接受此事件而调用事件的handler, Sender.ClassType既是调用CLASStype的事件句柄.

语句
as是一个运算符,她是用来做类的转换的..Sender 就指出送出信息的对象是 TControl.
with语句只是调用下面的语句.来完成程序.实际上没有什么关系的了啊

问题4:
Parent是指一个父类.从字面就可以看出的拉


有不足之处指出哦.
 
后退
顶部