On Fri, 6 Nov 2015, Martin Schreiber wrote:

On Friday 06 November 2015 18:33:54 Graeme Geldenhuys wrote:
On 2015-11-06 17:19, Michael Van Canneyt wrote:
With QMyVeryLongQueyObjectName as Q do
   try
     // Do things with Q
   finally
     Q.Close;
   end;

var
  Q: TQuery absolute QMyVeryLongQueyObjectName;
begin
  with Q do
    try
      // Do things with Q
    finally
      Q.Close;
    end;


problem solved! ;-)

Not a good idea IMHO, that hinders readability because one doesn't see the
real container at the "with" block start. Another important use of "with" is
to make complex address calculations only once at the "with" block start
without the need to define a pointer variable in "var" and to dereference in
every statement.

Indeed, and besides this:

a) it does not compile for properties. See below.
b) I did mention the requirement about non-trivial readable variable names...

Michael.

program Project1;

{$mode objfpc}

Type
  TMyType = class(TObject)
  private
    FM: TMyType;
    function GetM: TMyType;
    procedure SetM(AValue: TMyType);
  Public
    Procedure DoIt;
    Property MyVeryLongObjectPropertyName : TMyType Read GetM Write SetM;
  end;

function TMyType.GetM: TMyType;
begin
  Result:=Nil;
end;

procedure TMyType.SetM(AValue: TMyType);
begin
  //
end;

procedure TMyType.DoIt;

Var
  Q : TMyType absolute MyVeryLongObjectPropertyName; // Error !!!

begin

end;

begin
end.

--
_______________________________________________
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

Reply via email to