[Lazarus] 'with' is evil, isn't it?

Lukasz Sokol el.es.cr at gmail.com
Wed Aug 3 16:59:49 CEST 2011


On 03/08/2011 15:34, Michael Schnell wrote:
> On 08/03/2011 02:00 PM, Alexander Klenin wrote:
>> with a := MyCompomentList[0] do begin
>>    Rectangle(0, 0, a.Width, a.Height);
>> end;
> Here defining a as a pointer would do away with the with and the begin .. end.
> 
> By allowing for C-like defining of cariables we could write something like
> 
> 
>   var a TMyPointer := MyCompomentList[0];
> 
>  Rectangle(0, 0, a.Width, a.Height);
> 

Except that a here is _not_really_ _any_ variable... and neither it should be.

I think the idea [sh|w]ould be that

s/[identifier a]/MyComponentList[0] (plaintext substitution of 'a' with MyComponentList[0])
on the text block from begin to end should be transparent, 
(after the compiler checks the 'a' is correctly typed, hence my idea of telling
it _which_ type you're using of 'a' so it doesn't 'guess', but _check_ instead)
and THEN optimizations applied by compiler...

or ! if we want to be Pascal Explicit :

with MyComponentList[0] as a:TMyType do
begin

end;

(I guess somebody had this idea earlier but I suddenly like it for it's straightforward)

> 
> (this might or might not be a good idea)
> - Michael
> 

L.





More information about the Lazarus mailing list