Author Topic: Create empty safearray from scratch  (Read 2131 times)

0 Members and 1 Guest are viewing this topic.

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Create empty safearray from scratch
« on: August 28, 2010, 07:22:51 AM »
I have a simple function ListToArray that turns a one-dimensional list into a safearray. It checks for empty list because I haven't been able to create an empty safearray from scratch. Is this in anyway possible?

Code: [Select]
(defun ListToArray (typ lst)
  (if lst ; check for empty list
    (vlax-safearray-fill
      (vlax-make-safearray
        typ
        (cons 0 (1- (length lst)))
      )
      lst
    )
  )
)

Lee Mac

  • Seagull
  • Posts: 12922
  • London, England
Re: Create empty safearray from scratch
« Reply #1 on: August 28, 2010, 07:27:14 AM »
An empty variant:

Code: [Select]
(vlax-make-variant)

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Create empty safearray from scratch
« Reply #2 on: August 28, 2010, 07:35:43 AM »
Thanks for the quick answer. But an empty variant and an empty safearray are different "animals".

Code: [Select]
(type (ListToArray vlax-vbinteger '(1 2 3 4 5))) => SAFEARRAY
(type (vlax-make-variant)) => VARIANT

fixo

  • Guest
Re: Create empty safearray from scratch
« Reply #3 on: August 28, 2010, 10:59:42 AM »
What about this way

Code: [Select]
(vl-load-com)
(setq lst nil)
(repeat 99 (setq lst (cons (vlax-make-variant) lst)))
(setq sfar (vlax-safearray-fill
     (vlax-make-safearray vlax-vbvariant
       '(0 . 98))
     lst)
      )


Lee Mac

  • Seagull
  • Posts: 12922
  • London, England
Re: Create empty safearray from scratch
« Reply #4 on: August 28, 2010, 11:04:13 AM »
An empty safearray has a negative upper bound, but positive lower bound. However, you will throw an exception if you try to create this.

Atwist

  • Guest
Re: Create empty safearray from scratch
« Reply #5 on: August 28, 2010, 12:00:42 PM »
Hé Roy_043

Welcome on theswamp

Atwist


roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Create empty safearray from scratch
« Reply #6 on: August 28, 2010, 03:30:11 PM »
Thank you Atwist. We meet again!