Dynamic Collection Problems

  • Thread starter Thread starter Cor Ligthert [MVP]
  • Start date Start date
C

Cor Ligthert [MVP]

Matt,

You mean something as this?

\\\\
Dim a As New ArrayList
Dim b As String = ""
Dim c As Integer = 0
a.Add(b)
a.Add(c)
For Each obj As Object In a
Dim d As Type = obj.GetType
Debug.Write(d.ToString & vbCrLf)
Next
///

I hope this helps,

Cor
 
colgpaths(index). <-- this is my issue!
it NEEDS to be dynamic btw, and i want to access the objects
directly through the collection. not individual objects because
there is going to be 100's of them.

You can ask /any/ object what Type it is and work with it
accordingly, as in

If TypeOf colgpaths(index) Is OneOfMyClasses then
With DirectCast( colgpaths(index), OneOfMyClasses )
.Thing1()
.Thing2()
.Whatsit3 = 4
End With

ElseIf TypeOf colgpaths(index) Is SomeOtherClass then
' Cast it to the right type, and do things with it.

End If

HTH,
Phill W.
 
Hi Matt,

I would strongly consider Object orientation and the use of
Polymorphism, it looks like your making a game there and this is a good way
to create the objects for your engine. Sorry I can't be more specific in my
answer, but if you want an example of polymorphism i can direct you towards
something I made a while back.

http://members.lycos.co.uk/nickpatemanpwp/
My Own Software -> Starfield+

This is a basic GDI+ 3D engine that uses an object hierachy that can be
built upon really easily. It's always best to be strict with these kinds of
things because making your app "too" dynamic can open up a big can of worms!

Nick.
 
Hi All,

I have a little piece of code that is giving me the shits. I have an
arraylist colelction which is putting dynmaic objects into it, and the
objects are being accessed dynamically too. My problem is that .Net cant
intellisense dynmaic code, so how can i tell the collection that only a
certain type of object will be in there so that it can intellisense
properly? Also i want to be able to limit the object types that are
allowed into the array.

IS there any easier way to do either or both of these things than to
create my own collection class?

Thanks heaps,

Matt
 
This is the part of the code for those who wish to see it.


Private colGPaths As New Collections.ArrayList()

Public Overridable Sub DrawWall(ByVal x1 As Integer, ByVal y1 As
Integer, ByVal x2 As Integer, ByVal y2 As Integer)
Dim objGPath As New Drawing2D.GraphicsPath()
Dim index As Integer

index = colGPaths.Add(objGPath)
objGPath = Nothing

colgpaths(index). <-- this is my issue! it NEEDS to be dynamic btw,
and i want to access the objects directly through the collection. not
individual objects because there is going to be 100's of them.
End Sub
 
Hi Matt,

Unfortunately its really basic what I done with it, actually getting
reasonably 3d performance from GDI+ is crazy. That is certainly something I
would have liked to have put in but didnt get that far unfortunately, along
with flat facet shading, I'm no maths expert and some of those equations are
mind numbing for me.

Yeah it's all open source, and pretty straight forward code, although I
havent commented particularly much (if at all). In respect to finding out
how to produce 2d selection on a 3d plane I think you should check out some
game development sites, such as http://www.gamasutra.com/. Finding these
algorithms can be a royal pain I'm sure youll agree :-(

Take care.

Nick Pateman.
 
Thanks Nick.

I'm actually writing a program that draws the 2D x,y,z planes and a 3D
drawing of the structure. Similar to that of a housing architect
program. It has to be fairly quick and be able to detect mouse movements
over each individual object so i can change properties in runtime by
right clikcing on a wall or a roof. At the moment im using th isvisible
and isoutlinevisible mothods to detect this. Does Starfield+ do these
things as well? I assume its open source?

Cheers,

Matt

PS. I like dynamic :P
 
Bingo!

DirectCast!

That was exactly what i was looking for. Thanks Phil.

I couldnt find anything on microsofts msdn that would do this. Obviously
i was searching for the wrong thing.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top