Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 3 of 3 total
Thread Is this a Horse I see before me?
Thu, Sep 1 2016 4:24 AMPermanent Link

Matthew Jones

I was thinking, after listening to a podcast on development, that the
lack of an "out" or "var" parameter type was something that is not hard
to overcome, if my thinking is right. So let me present the thought:

procedure GetSomething(var AValue : Integer);

This is a common thing in Delphi - passing a value and having it
returned. But in Javascript, you can't do this, so WebBuilder cannot
either. But you can pass an object. So why not just make an object just
for this purpose?

procedure GetSomething(outValue : TOutValue);

Then you can do:

 // code
 GetSomething(outValue);
 Response := outValue.IntValue;
 // use it

That is working right? To make it work, you need a simple class with

TOutValue = class
public
property IntValue : Integer;
property StringValue : String;
end;

And to use it, you unfortunately have to create an instance either
locally, in the class, in the unit, or globally, and pass that as the
parameter. But is this a way to overcome the restriction as I think? Or
am I mad? (In this regard, not generally)

Now, far be it for me to suggest that this could become a part of the
language, with automatically created local TOutValues (or TIntOutValue
or whatever) in the background when you happen to type var in front of
a parameter...


--

Matthew Jones


(Horse? I am referring to "getting a coach and horses through" a
restriction, as we say in the UK. Most days.)
Tue, Sep 6 2016 8:02 AMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Matthew,

<< And to use it, you unfortunately have to create an instance either locally, in the class, in the unit, or globally, and pass that as the parameter. But is this a way to overcome the restriction as I think? Or am I mad? (In this regard, not generally) >>

No, it definitely can be done.  The reason why I didn't do it is:

1) You can normally work around the lack of this feature.
2) It makes the emitted JS code look quite a bit different than the Object Pascal code.
3) It can (not always) stress the garbage collector, if used enough.  Each object has to be allocated on the heap, due to possible nesting, closures, etc.

Tim Young
Elevate Software
www.elevatesoft.com
Tue, Sep 6 2016 8:40 AMPermanent Link

Matthew Jones

Tim Young [Elevate Software] wrote:

> No, it definitely can be done.  The reason why I didn't do it is:
>
> 1) You can normally work around the lack of this feature.
> 2) It makes the emitted JS code look quite a bit different than the
> Object Pascal code.  3) It can (not always) stress the garbage
> collector, if used enough.  Each object has to be allocated on the
> heap, due to possible nesting, closures, etc.

Thanks. So could be used if one gets stuck, but so far I haven't been
stuck on this "restriction". Once you know it is there, it is a
non-issue really.

--

Matthew Jones
Image