Has anyone any idea why I cannot do the following in a class inherited
from ArrayList?
Public Shadows Function toArray() As Rectangle()
Return (MyBase.ToArray())
End Function
I can do this with other objects, but seemingly not objects in the
drawing namespace (I'm sure there must be others), any idea how I get around
this?
Nick.
It doesn't work because Rectangle is a value type (Structure) and is
boxed to be stored in an ArrayList. Getting the rectangle back out
requires unboxing.
Mattias
--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/
Please reply only to the newsgroup.
As Mattias said Rectangle is a value type and would need to be unboxed, the
ArrayList.ToArray does not automatically unbox value types.
I would define a new Rectangle array of the size (ArrayList.Count - 1)
needed than using a for to loop, assign the values from the ArrayList to
this new Array.
Hope this helps
Jay
"Nak" <a...@a.com> wrote in message
news:erSqJoWa...@TK2MSFTNGP12.phx.gbl...
I understand the ToArray method not working now thanks to Mattias, I had
just presumed that it was an Object, but never mind.
The reason I am inheriting from arraylist is because I want features
such as "AddRange" and such like that I cannot get from CollectionBase, I
have tested the collection and it works very well, what are you saying
shouldn't work? It works just the same as my previous named collections
just by using inheritance rather than declaring a private arraylist and
exposing it's methods. Are you saying that I shouldn't be shadowing? I am
shadowing because I wish the class to be strongly named, for example I wish
to add to the collection via it's own type not just object. Maybe I'm doing
it the wrong way but it seems to work perfectly so far, here is an example
of a listviewitem collection of mine, is it wrong?
----------------------------------------------------
Public Class listViewItem_Collection
Inherits ArrayList
#Region "Property interface"
Public Shadows Property item(ByVal iIndex As Integer) As
ListViewItem
Get
Return (MyBase.Item(iIndex))
End Get
Set(ByVal Value As ListViewItem)
MyBase.Item(iIndex) = Value
End Set
End Property
#End Region
#Region "New / Finalize"
Public Sub New()
Call MyBase.New(initialArrayListMaxCapacity)
End Sub
Protected Overrides Sub Finalize()
Call MyBase.Finalize()
End Sub
#End Region
#Region "Public methods"
Public Shadows Function add(ByVal iListViewItem As ListViewItem) As
Integer
Return MyBase.Add(iListViewItem)
End Function
Public Shadows Sub addRange(ByVal iListViewItem() As ListViewItem)
Call MyBase.AddRange(iListViewItem)
End Sub
Public Shadows Sub addRange(ByVal iListViewItemCollection As
listViewItem_Collection)
Call MyBase.AddRange(iListViewItemCollection)
End Sub
Public Shadows Function contains(ByVal iListViewItem As
ListViewItem) As Boolean
Return (MyBase.Contains(iListViewItem))
End Function
Public Shadows Function indexOf(ByVal iListViewItem As ListViewItem)
As Integer
Return (MyBase.IndexOf(iListViewItem))
End Function
Public Shadows Function insert(ByVal iIndex As Integer, ByVal
iListViewItem As ListViewItem)
Call MyBase.Insert(iIndex, iListViewItem)
End Function
Public Shadows Function insertRange(ByVal iIndex As Integer, ByVal
iListViewItem() As ListViewItem)
Call MyBase.InsertRange(iIndex, iListViewItem)
End Function
Public Shadows Function insertRange(ByVal iIndex As Integer, ByVal
iListViewItemCollection As listViewItem_Collection)
Call MyBase.InsertRange(iIndex, iListViewItemCollection)
End Function
Public Shadows Function lastIndexOf(ByVal iListViewItem As
ListViewItem) As Integer
Return (MyBase.LastIndexOf(iListViewItem))
End Function
Public Shadows Sub remove(ByVal iListViewItem As ListViewItem)
Call MyBase.Remove(iListViewItem)
End Sub
Public Shadows Function repeat(ByVal iListViewItem As ListViewItem,
ByVal iCount As Integer) As listViewItem_Collection
Return (MyBase.Repeat(iListViewItem, iCount))
End Function
Public Shadows Sub setRange(ByVal iIndex As Integer, ByVal
iListViewItemCollection As listViewItem_Collection)
Call MyBase.SetRange(iIndex, iListViewItemCollection)
End Sub
Public Shadows Sub setRange(ByVal iIndex As Integer, ByVal
iListViewItem() As ListViewItem)
Call MyBase.SetRange(iIndex, iListViewItem)
End Sub
Public Shadows Function toArray() As ListViewItem()
Return (MyBase.ToArray())
End Function
#End Region
End Class
----------------------------------------------------
Take note that I am only shadowing methods or properties that refer to type
"Object".
Nick.
"Jay B. Harlow [MVP - Outlook]" <Jay_H...@email.msn.com> wrote in message
news:OZl8PGYa...@TK2MSFTNGP10.phx.gbl...
Derive from CollectionBase, then every place in your code you are using
ByBase, use InnerList. Drop all the Shadows keywords.
If there is a chance you will use this collection via IList, override
OnValidate
Public Class listViewItem_Collection
Inherits CollectionBase
Public Function Add(ByVal iListViewItem As ListViewItem) _
As Integer
Return InnerList.Add(iListViewItem)
End Function
Public Sub AddRange(ByVal iListViewItem() As ListViewItem)
InnerList.AddRange(iListViewItem)
End Sub
' use for extra protection, if this collection will be accessed
' via the IList interface.
Protected Overrides Sub OnValidate(ByVal value As Object)
If Not TypeOf value Is ListViewItem Then
Throw New InvalidCastException
End If
End If
End Class
Also do not define Finalize unless you really need to Finalize (not just
calling the base Finalize). Your object will linger in memory much longer
then it needs to.
Hope this helps
Jay
"Nak" <a...@a.com> wrote in message
news:OVO6WQYa...@tk2msftngp13.phx.gbl...
Thanks for the advice, I had no idea there was an inner list, I saw a
small example of inheriting from ArrayList but the example didn't mention
InnerList (not that I am aware of anyway, and not that I am renowned for my
reading skills). Thanks again, I shall modify my code to always inherit
from CollectionBase :-)
Nick.
P.S. The empty finalize code was only there as I had previously removed
license disposing code and forgot to remove the rest :-)
"Jay B. Harlow [MVP - Outlook]" <Jay_H...@email.msn.com> wrote in message
news:%238XJEeY...@TK2MSFTNGP09.phx.gbl...
But then again, that's no excuse, I should have checked, sorry.
Nick.
:-(
Nick.
"Nak" <a...@a.com> wrote in message
news:O8wJRBZ...@TK2MSFTNGP10.phx.gbl...
CollectionBase.InnerList: represents the contained ArrayList itself, the On*
overridable methods will not be called (read InnerList has no validation).
CollectionBase.List: represents the 'logical' IList interface that
CollectionBase implements, the On* overridable methods will be called (read
List has validation).
Most of the time you want to use CollectionBase.InnerList property,
sometimes you need to use the CollectionBase.List property. For example, use
List.Add if you want to attach event handlers no matter how the item was
added, then override OnAdd to add the handlers...
Hope this helps
Jay
"Nak" <a...@a.com> wrote in message
news:%23M7oG8Y...@tk2msftngp13.phx.gbl...
If sorting was a "true" requirement, I would probably write my own
SortedDictionaryBase that contains a SortedList object. That has an
interface similiar to DictionaryBase. Most of the methods on
SortedDictionaryBase would delegate to the SortedList.
Hope this helps
Jay
"Nak" <a...@a.com> wrote in message
news:%23BQQlEZ...@TK2MSFTNGP12.phx.gbl...
Thanks so much, :-) I shall try it the second I get a spare moment,
thanks for your efforts they are much appreciated. I can't wait to try it
out, thanks again :-)
Nick.
"Jay B. Harlow [MVP - Outlook]" <Jay_H...@email.msn.com> wrote in message
news:OGCvYKba...@TK2MSFTNGP09.phx.gbl...
> Nak,
> Attached are extended CollectionBase & DictonaryBase classes, that should
do
> what you want.
>
> I wrote them to mimic CollectionBase & DictionaryBase as close as
possible.
> The differences being is they have a constructor that you can pass the
inner
> container to the constructor. And the InnerList changed to an IList type,
> while InnerHashtable changed to InnerDictionary of type IDictionary.
>
> ExCollectionBase accepts an IList in the constructor, if you do not give
> one, ArrayList is used. For example you could pass an array of objects,
> making a fixed size list, instead of an ArrayList. InnerList does not do
> validation, List does validation.
>
> ExDictionaryBase accepts an IDictionary in the constructor, if you do not
> give one, HashTable is used. For example you can pass SortedList,
> HybridDictionary, ListDictionary, instead of a HashTable. InnerDictionary
> does not do validation, Dictionary does validation.
>
> You can derive from ExDictionaryBase then pass a new SortedList to the
> constructor.
>
> Something like:
> Public Class NakSortedList
> Inherits ExDictionaryBase
>
> Public Sub New()
> MyBase.New(New SortedList)
> End Sub
>
> ' other methods you want
>
> End Class
>
> FWIW: I actually started with the m_dictionary field in ExDictionaryBase
as
> type SortedList, but then noticed I did not rely on it specifically being
a
> SortedList, so I modified ExDictionaryBase to support any IDictionary,
> which IMHO actually makes the class far more flexible.
>
> If you use them, let me know if you find any problems with them.
>
> Hope this helps
> Jay
>
> "Nak" <a...@a.com> wrote in message
> news:%23BQQlEZ...@TK2MSFTNGP12.phx.gbl...
Public Sub AddRange(items() As Object)
--
Happy to help,
-- Tom Spink
(thomas...@ntlworld.com)
"Go down with your server"
http://dotnetx.betasafe.com >> On The Mend
Please respond to the newsgroup,
so all can benefit
"Nak" <a...@a.com> wrote in message
news:OVO6WQYa...@tk2msftngp13.phx.gbl...
I think you missed the point, I don't want Object as the type, I wanted
Rectangle, but don't worry about it, they put me straight on that one,
Rectangle is a structure and not an object, hence it not type casting.
Nick.
"Tom Spink" <thomas...@ntlworld.com> wrote in message
news:e1u6mCca...@TK2MSFTNGP09.phx.gbl...
--
Happy to help,
-- Tom Spink
(thomas...@ntlworld.com)
"Go down with your server"
http://dotnetx.betasafe.com >> On The Mend
Please respond to the newsgroup,
so all can benefit
"Nak" <a...@a.com> wrote in message
news:#dxRaPca...@TK2MSFTNGP09.phx.gbl...
"Tom Spink" <thomas...@ntlworld.com> schrieb:
> Ha, sorry, I clicked send before I'd finished my message, my mistake.
> Actually, I pressed Ctrl+Enter, because I was in that sort of mood
> ;-))) <g>
In my German OE Ctrl+Enter will store the message in the Drafts folder,
Alt+Enter is used to send a message.
Regards,
Herfried K. Wagner
--
MVP · VB Classic, VB .NET
http://www.mvps.org/dotnet
--
Happy to help,
-- Tom Spink
(thomas...@ntlworld.com)
"Go down with your server"
http://dotnetx.betasafe.com >> On The Mend
Please respond to the newsgroup,
so all can benefit
"Herfried K. Wagner [MVP]" <hirf...@m.activevb.de> wrote in message
news:OgVPKwna...@tk2msftngp13.phx.gbl...
Pressing 2 keys at once huh? I'll leave that to the pros! ;-)
Nick
"Tom Spink" <thomas...@ntlworld.com> schrieb:
> I'd just been using an irritating program, where to add another line
in a
> multiline textbox, you have to press Ctrl+Enter. Enter will accept the
> entry, but I wanted multiline. I was still in Ctrl+Enter mode.
Which newsreader do you use?
The shortcut key Alt+Enter brings up properties, as it does for shell
objects, and I've just confirmed it by using Ctrl+Enter to send this
message, wierd no?
--
Happy to help,
-- Tom Spink
(thomas...@ntlworld.com)
"Go down with your server"
http://dotnetx.betasafe.com >> On The Mend
Please respond to the newsgroup,
so all can benefit
"Herfried K. Wagner [MVP]" <hirf...@m.activevb.de> wrote in message
news:eHsKEDpa...@tk2msftngp13.phx.gbl...
--
Happy to help,
-- Tom Spink
(thomas...@ntlworld.com)
"Go down with your server"
http://dotnetx.betasafe.com >> On The Mend
Please respond to the newsgroup,
so all can benefit
"Nak" <a...@a.com> wrote in message
news:e5fgQ2oa...@tk2msftngp13.phx.gbl...
Haha, as opposed to?
Nick.
"Tom Spink" <thomas...@ntlworld.com> schrieb:
> OE, English, 6.00.2800.1106
I saw this in the message's properties.
> The shortcut key Alt+Enter brings up properties, as it does for shell
> objects, and I've just confirmed it by using Ctrl+Enter to send this
> message, wierd no?
Really wierd.
--
Happy to help,
-- Tom Spink
(thomas...@ntlworld.com)
"Go down with your server"
http://dotnetx.betasafe.com >> On The Mend
Please respond to the newsgroup,
so all can benefit
"Nak" <a...@a.com> wrote in message
news:eW8ediua...@TK2MSFTNGP09.phx.gbl...
Nick.
"Tom Spink" <thomas...@ntlworld.com> wrote in message
news:%23io88$xaDHA...@tk2msftngp13.phx.gbl...
--
Happy to help,
-- Tom Spink
(thomas...@ntlworld.com)
"Go down with your server"
http://dotnetx.betasafe.com >> On The Mend
Please respond to the newsgroup,
so all can benefit
"Nak" <a...@a.com> wrote in message
news:O$V$7KzaDH...@TK2MSFTNGP09.phx.gbl...
What's a "Naturlich" when it's at home?
Nick.
But what does it mean?
Nick.
"Nak" <a...@a.com> schrieb:
> > Natürlich.
>
> But what does it mean?
adj.: natural, normal,
adv.: naturally, of course
--
Happy to help,
-- Tom Spink
(thomas...@ntlworld.com)
"Go down with your server"
http://dotnetx.betasafe.com >> On The Mend
Please respond to the newsgroup,
so all can benefit
"Herfried K. Wagner [MVP]" <hirf...@m.activevb.de> wrote in message
news:OI5k0t8...@tk2msftngp13.phx.gbl...
--
Happy to help,
-- Tom Spink
(thomas...@ntlworld.com)
"Go down with your server"
http://dotnetx.betasafe.com >> On The Mend
Please respond to the newsgroup,
so all can benefit
"Tom Spink" <thomas...@ntlworld.com> wrote in message
news:uExeDp9a...@tk2msftngp13.phx.gbl...
"Tom Spink" <thomas...@ntlworld.com> schrieb:
> I haven't got a diaresis (umlaut) key, and I also haven't got enough RAM
to
> load CharMap ;-) LOL
Maybe you should close VS .NET.
;-)))
--
HTH,
-- Tom Spink, Über Geek
Please respond to the newsgroup,
so all can benefit
"Herfried K. Wagner [MVP]" <hirf...@m.activevb.de> wrote in message
news:O#b4LR#aDHA...@TK2MSFTNGP12.phx.gbl...
Not that you don't deserve one of course Herfried I'm sure ;-)
Nick.
"Tom Spink" <thomas...@ntlworld.com> wrote in message
news:uieQ7q9a...@TK2MSFTNGP12.phx.gbl...
"Cor" <n...@non.com> schrieb:
A good idea. I hate the "Umlaute" and i hate the "ß" character in the
German language (I always write "ss" instead of "ß").
Some developers use umlauts when naming their variables *brrr*.
Umlaut sensitive sounds intriguing, and I have to agree with you, Herfried,
about the s-zet letter. I prefer ss.
Ich heisse Tom oder Ich heiße Tom?
--
HTH,
-- Tom Spink, Über Geek
Please respond to the newsgroup,
so all can benefit
"Herfried K. Wagner [MVP]" <hirf...@m.activevb.de> wrote in message
news:eb#oHSBbD...@TK2MSFTNGP12.phx.gbl...
--
HTH,
-- Tom Spink, Über Geek
Please respond to the newsgroup,
so all can benefit
"Herfried K. Wagner [MVP]" <hirf...@m.activevb.de> wrote in message
news:udDmcjAb...@tk2msftngp13.phx.gbl...
> -- Tom Spink, Über Geek
Nick.
--
HTH,
-- Tom Spink, Über Geek
Please respond to the newsgroup,
so all can benefit
"Nak" <a...@a.com> wrote in message
news:OK6tYhCb...@TK2MSFTNGP09.phx.gbl...