473,386 Members | 1,702 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Dynamic Collection Problems

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
Nov 21 '05 #1
7 1260
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
Nov 21 '05 #2
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
Nov 21 '05 #3
"Matt" <ma*****@interactiveideasandsolutions.com> wrote in message
news:eX**************@TK2MSFTNGP14.phx.gbl...
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.
Nov 21 '05 #4
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.

"Matt" <ma*****@interactiveideasandsolutions.com> wrote in message
news:eX**************@TK2MSFTNGP14.phx.gbl...
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

Nov 21 '05 #5
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
Nick Pateman wrote:
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.

"Matt" <ma*****@interactiveideasandsolutions.com> wrote in message
news:eX**************@TK2MSFTNGP14.phx.gbl...
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


Nov 21 '05 #6
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.
Phill. W wrote:
"Matt" <ma*****@interactiveideasandsolutions.com> wrote in message
news:eX**************@TK2MSFTNGP14.phx.gbl...

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.

Nov 21 '05 #7
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.

"Matt" <ma*****@interactiveideasandsolutions.com> wrote in message
news:Om*************@TK2MSFTNGP15.phx.gbl...
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
Nick Pateman wrote:
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.

"Matt" <ma*****@interactiveideasandsolutions.com> wrote in message
news:eX**************@TK2MSFTNGP14.phx.gbl...
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



Nov 21 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Roel Wuyts | last post by:
CALL FOR CONTRIBUTIONS International Workshop on Revival of Dynamic Languages http://pico.vub.ac.be/~wdmeuter/RDL04/index.html (at OOPSLA2004, Vancouver, British Columbia, Canada, October...
6
by: MikeY | last post by:
Hi Everyone, Does anyone know where I can get my hands on a sample with source code of a simple dynamic button control in C# Windows form. I am looking for a sample that uses a class library...
2
by: Brian | last post by:
NOTE ALSO POSTED IN microsoft.public.dotnet.framework.aspnet.buildingcontrols I have solved most of my Server Control Collection property issues. I wrote an HTML page that describes all of the...
2
by: cindy | last post by:
I have a web form with 3 links, depending on which link is clicked a user control loads, page1.ascx,page2.ascx,page3.ascx page1.ascx does a search, uses 3 asp:dropdownlists with viewstate true...
3
by: NateDawg | last post by:
I'm reposting this. I'm kinda in a bind untill i get this figured out, so if anyone has some input it would sure help me out. Ok, I’ve noticed a few gridview problems floating around the forum....
8
by: novus | last post by:
Hi, In ASP.net 2.0 I make a control which add the same controls dynamically. In the oninit event I add the controls to the controls collection. After that the loadviewstate event fills in the...
4
by: Tomassus | last post by:
Hi there, I have a problem with dynamic memory allocation. I know that it would have been easier to use vectors methods, but i want to know what i do here wrong. This is one of my methods in...
2
by: englishman69 | last post by:
Hello, I have been banging my head against this one for a while... Searches online have revealed many different proposals for correcting my issue but none that I can follow! My basic situation...
2
by: Peted | last post by:
Can anyone suggest a best practice approach to building a dynamic winforms UI. Just as an example somehting like a billing application where you enter a customer billing data and the billing...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.