testcastsimple.out

来自「格式化源码的最新板」· OUT 代码 · 共 89 行

OUT
89
字号
unit testcastsimple;

interface

uses Classes, StdCtrls;

var
  lcstrings: TStringList;
  lcobj:     TObject;
  lcbutton:  TButton;

implementation

procedure testdot;
var
  lc: TObject;
begin
  lc := lcbutton.owner;
  lc := (lcobj as TComponent).owner;
end;

procedure test1;
begin
  (lcbutton as TObject).Free;
  (lcobj as TStringList).Free;
  (lcstrings as TObject).Free;
end;

procedure testsurplusbrackets;
begin
  ((lcbutton as TObject)).Free;
  (((lcobj as TStringList))).Free;
  ((((lcstrings as TObject)))).Free;
end;

procedure testsurplusbrackets2;
begin
  lcbutton.parent.parent.owner.Free;
  (lcbutton.parent.parent).owner.Free;
  ((lcbutton.
    parent).parent).owner.Free;
  (((lcbutton).parent).parent).owner.Free;
  ((((lcbutton).
    parent).parent).owner).Free;
end;

procedure test2;
var
  lc: TObject;
begin
  lc := (lcbutton as TObject);
  lc := (lcobj as TStringList);
  lc := (lcstrings as TObject);
  lc := (lcstrings);
end;

procedure test3;
begin
  if lcobj is TStrings then
    (lcobj as TStrings).ClassName;
  if lcobj is TStrings then
  begin
    ((lcobj as TStrings)).ClassName;
  end;
end;

procedure test4;
var
  lc: TObject;
begin
  lc := (lcobj as TComponent).owner;
  lc := ((lcobj as TComponent).owner as TButton);
  lc := (((lcobj as TComponent).owner as TButton).owner as TButton);
  lc := ((((lcobj as TComponent).owner as TButton).owner as TButton).owner as TButton);
  lc := ((lcobj as TObject) as TComponent);
  lc := (((lcobj as TButton) as TObject) as TComponent);
  lc := ((lcobj as TComponent).owner as TComponent);
  lc := (((lcobj as TButton) as TObject).owner as TComponent);
  lc := ((((((lcobj as TButton)) as TObject)).owner as TComponent));
  lc := (lcbutton.parent as TComponent).owner;
  lc := (lcbutton.parent.parent as TComponent).owner;
  lc := (lcbutton.parent.parent).owner;
  lc := ((lcbutton.parent).parent).owner;
  lc := (((lcbutton).parent).parent).owner;
  lc := ((((lcbutton).parent).parent).owner);
end;

end.
 

⌨️ 快捷键说明

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