Why is Self assignable in Delphi?

后端 未结 5 914
星月不相逢
星月不相逢 2021-01-04 02:17

This code in a GUI application compiles and runs:

procedure TForm1.Button1Click(Sender: TObject);
begin
  Self := TForm1.Create(Owner);
end;
<
5条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-04 02:24

    Assigning to Self is so illogical and useless that this 'feature' is probably an oversight. And as with assignable constants, it's not always easy to correct such problems.

    The simple advice here is: don't do it.

提交回复
热议问题