Reference object instance created using “with” in Delphi

后端 未结 9 1404
生来不讨喜
生来不讨喜 2020-12-03 18:17

is there a way to reference an object instance that is created using the \"with\" statement?

Example:

with TAnObject.Create do
begin
  DoSomething(in         


        
9条回答
  •  星月不相逢
    2020-12-03 19:00

    This is not possible now, but we can make it a reality by persuading the compiler creators:

      With TForm1.Create (Nil) Do  // New TForm1 instance
        Try
          LogForm (");  // That same instance as parameter to an outer method (solution)
          "ShowModal;  // Instance.ShowModal
        Finally
          "Free;  // Instance.Free
        End;
    

    My proposal is:

    1. No more than one object/record per With header.
    2. Nested Withs not allowed.
    3. Usage of " to indicate the object/record (double quotes are similar to the ditto mark: http://en.wikipedia.org/wiki/Ditto_mark).

提交回复
热议问题