On Sun, 21 Jul 2019, Simon Ameis wrote:

Hello all,

I'm currently defining some external classes for my JSON data payload
which contains some array elements.

So far I got two solutions:

The first one uses "pascal arrays". This gives a lot of type safety but
there are no array helpers yet which make requires me to use the pascal
way of manipulating the array.

As far as I know, array helpers should work ?

What is missing on the arrays ? I think Copy, insert, Concat should all work.
What else do you need ?


Tmyarraytype = array of TJSObject;
tmyclass = class external name 'abc' (TJSObject)
property myarray: Tmyarraytype read fmyarray;
end;

However there is TJSArray class which contains a lot of usefull methods
which are available on all JavaScript arrays. Thus the second solution is:

tmyclass = class external name 'abc' (TJSObject)
property myarray: TJSArray read fmyarray;
end;

Then I have all the methods but no type safety at all and I need to do
typecast for each array access.

I think this would be an ideal case for using generics. Are there any
plans to implement TJSArray as generic as soon as generics are supported
by pas2js?

Yes. The default TJSArray will then just be a specialization using JSValue.
Do not forget that a javascript array is not typed: it can contain any
element.

Same for promise and some other things which will be reworked using
generics (low-level buffers)

Michael.
_______________________________________________
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel

Reply via email to