Delphi学习手记

来源:互联网 发布:如何做好一名淘宝客服 编辑:程序博客网 时间:2024/05/22 04:39

本人一直使用C++  Buider,并开发了一个"供应商关系管理"的三层应用系统.
现公司要求使用DELPHI,没办法只有重新学习PASCAL语言.
便记录学习的过程,那就叫Delphi学习手记吧.
<1> 好象Inherit Form不行,如果想覆盖上边的方法,重写事件或函数,竟然报错,不懂先,是不是Inherit不同.
    经过测试,是可以的,而且可以添加你的方法;
  procedure TForm2.Button3Click(Sender: TObject);
begin
 inherited;
  ShowMessage('a');
end;
<2>Abstract methods  (抽象方法)
抽象方法是虚方法或动态方法,并且在声明它的类中没有实现,而是由它的派生类中实现.
procedure DoSomething;virtual;abstract

<3> 指定创建何种控件: 写给函数
如下:

 function TForm1.CreateControl(ControlClass:TControlClass;
       Const ControlName:String;X,Y,W,H:Integer):TControl;
  begin
   Result:=ControlClass.Create(self);
   with Result do
   begin
    Parent:=Self;
    Name:=ControlName;
    SetBounds(X,Y,W,H);
    Visible:=true;
    end;
  end;

调用:
            CreateControl(TPageControl,'PageControl1',10,10,100,20);

<4> Object is Class  用来验证一个运行的控件的实际类型.
  if ActiveControl is TEdit then TEdit(ActiveControl).SelectAll;

<5>  Object as Class  as运算符执行受检查的类型转换;
  列:        
        procedure TForm1.Button2Click(Sender: TObject);
begin
  With Sender as TButton do
   begin
    Caption:='&OK';
    OnClick:=Button1Click;
    end;
end;

或者:   
            (Sender as TButton).Caption:='&OK';
            (Sender as TButton).OnClick:=Button1Click;