fmmain.pas

来自「多数代码可以直接在Delphi6和Delphi7环境下运行。部分涉及.NET技术」· PAS 代码 · 共 89 行

PAS
89
字号
unit fmMain;

interface

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

type
  TForm1 = class(TForm)
    Button1: TButton;
    CheckBox1: TCheckBox;
    RadioButton1: TRadioButton;
    Memo1: TMemo;
    Button2: TButton;
    mmResult: TMemo;
    Button5: TButton;
    Button6: TButton;
    procedure Button5Click(Sender: TObject);
    procedure Button6Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

  TBase = class(TObject)
  private
    iID : Integer;
    dValue : Double;
    sName : String;
  public
    procedure SetName(const sName : String );
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button5Click(Sender: TObject);
var
  aObj : TComponent;
  aButton : TButton;
  alb : TListBox;
  aForm : TForm1;
begin
  aObj := TComponent(TButton.NewInstance);
  aObj.Create(Self);
  aButton := TButton(aObj);
  aButton.Caption := 'I am a Button';

  if (aObj is TListBox) then
  begin
    alb := TListBox(aObj);
    alb.Items.Add('Test');
  end;

  if (aObj is TForm1) then
  begin
    aForm := TForm1(aObj);
    aForm.Caption := 'I am a Form';
    aForm.WindowState := wsNormal;
    aForm.ShowModal;
  end;
end;

procedure TForm1.Button6Click(Sender: TObject);
var
  aBObj : TBase;
  aObj : TObject;
begin
  aObj := TObject(TBase.NewInstance.Create);
  ShowMessage(aObj.ClassName);
  aBObj := TBase(aObj);
  ShowMessage(aBObj.ClassName);
end;

{ TBase }

procedure TBase.SetName(const sName: String);
begin
  Self.sName := sName;
end;

end.

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?