3

What is the method, using Delphi XE2, to call to add Array definition to a dwsUnit component at runtime?

MyDwsUnit.Arrays.Add returns a TCollectionItem, not TdwsArray, while adding an array definition at design time adds a TdwsArray instance!.

Ken White
  • 123,280
  • 14
  • 225
  • 444
Bahaa
  • 123
  • 2
  • 9

1 Answers1

3

Default TCollection.Add method returns a TCollectionItem, even though it's actually an instance of whatever items the collections manages (this isn't specific to DWScript, it's a Delphi VCL thing).

To simplify that, most subclassed collections in DWScript now reintroduce an Add method that will wrap the default one with a cast, so you don't have to do the cast manually. So chances are you're on older version of DWScript.

If you don't want to update, you can just use

(MyDwsUnit.Arrays.Add as TdwsArray)

instead.

Eric Grange
  • 5,931
  • 1
  • 39
  • 61
  • Thank you Eric. You are right, i am on V2.2 (sorry i forget to mention this). Will update once V2.3 is stable. i used :var ArrayVar:TdwsArray; begin ArrayVar := TdwsArray.Create(FMainUnit.Arrays); and it works. thanks again. – Bahaa Oct 05 '12 at 05:50