473,320 Members | 1,993 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,320 software developers and data experts.

Find Object Data Type

Shashi Sadasivan
1,435 Expert 1GB
Hi,
i wanted to make a generec fntions which will compare a given object type against a lit of objects.

my list of object are a set of forms, but sor simplicity lets assume it to be a lit of int, string, float, decimal, etc

my function should get a parameter which is an int,string,etc
inside we have to check if any object within the list is the same data type as the parameter.

Is there any predefined Data Type or some similar method?

thanks
Sep 5 '07 #1
7 1371
r035198x
13,262 8TB
Hi,
i wanted to make a generec fntions which will compare a given object type against a lit of objects.

my list of object are a set of forms, but sor simplicity lets assume it to be a lit of int, string, float, decimal, etc

my function should get a parameter which is an int,string,etc
inside we have to check if any object within the list is the same data type as the parameter.

Is there any predefined Data Type or some similar method?

thanks
C# has the is operator.
Also all objects are inherit from System.Object so they all have the GetType method.
Sep 5 '07 #2
Shashi Sadasivan
1,435 Expert 1GB
Ok, cool, thank for that !
howevere if this is my method

Expand|Select|Wrap|Line Numbers
  1. private Form checkForms(<FormDataType> frm)
  2. {
  3.    foreach(Form f in this.MdiChildren)
  4.    {
  5.       if(f is frm)
  6.            return f;
  7.    }
  8.    return null;
  9. }
So that is what my code should look like... I cant think of the parameter datatype (ie <FormDataType>) if i have 3 forms namely frm1,frm2,frm3
I wuold like to go throug each MDIChild, and if it matches frm1/2/3 (which ever is sent as a param) it should return the mdiChild so that i can focus it.
At the moment, I instantiate the form object, and compare the names of the mdiChildren (for some reson it dosent work, but will work on it)
Is there any other way especially with the datatype that i should be sending?
Sep 5 '07 #3
r035198x
13,262 8TB
Ok, cool, thank for that !
howevere if this is my method

Expand|Select|Wrap|Line Numbers
  1. private Form checkForms(<FormDataType> frm)
  2. {
  3.    foreach(Form f in this.MdiChildren)
  4.    {
  5.       if(f is frm)
  6.            return f;
  7.    }
  8.    return null;
  9. }
So that is what my code should look like... I cant think of the parameter datatype (ie <FormDataType>) if i have 3 forms namely frm1,frm2,frm3
I wuold like to go throug each MDIChild, and if it matches frm1/2/3 (which ever is sent as a param) it should return the mdiChild so that i can focus it.
At the moment, I instantiate the form object, and compare the names of the mdiChildren (for some reson it dosent work, but will work on it)
Is there any other way especially with the datatype that i should be sending?
It doesn't look like you are comparing types then. The "is" operator is used to check whether the run-time type of an object is compatible with a given type.
If you want to check for equality you should use the Equal method instead.
Sep 5 '07 #4
Shashi Sadasivan
1,435 Expert 1GB
thanks anyways,
i have taken the longer approach. I hope i will get the more generic one worked out some other day.
Atthe end of this day, made it work good
Sep 5 '07 #5
Plater
7,872 Expert 4TB
You should use "Object" as the type for the argument you pass in.

Although I don't know what this accomplishes as you already have your frm1 frm2 frm3 objects available to you.
Sep 5 '07 #6
Shashi Sadasivan
1,435 Expert 1GB
You should use "Object" as the type for the argument you pass in.

Although I don't know what this accomplishes as you already have your frm1 frm2 frm3 objects available to you.
its something like amdi parent with 3 buttons to open the 3 different forms.
but there can only be one instance of each form, so if any of the button is clicked, the form type is sent to this method which searches all the forms contained in that mdiparent if it is of that form type.
if i pass an object, i would have to instantiate it and then discard it later.
Sep 5 '07 #7
Plater
7,872 Expert 4TB
Could you not just disable the button when the child window is created and then when it is closed re-enable the button?
Sep 5 '07 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Chris Fink | last post by:
This should be relatively simple but I am unable to find an asp:button tag in a datalist footer. I have tried it numerous ways including the FindControl method from the many events that the...
27
by: one man army | last post by:
Hi All- I am new to PHP. I found FAQTS and the php manual. I am trying this sequence, but getting 'no zip string found:'... PHP Version 4.4.0 $doc = new DomDocument; $res =...
5
by: SunnyDrake | last post by:
HI! I wrting some program part of it is XML config parser which contains some commands(for flexibility of engenie). how do i more simple(if it possible not via System.Reflection or...
18
by: Neehar | last post by:
Hello For one of the interviews I took recently, I was given an offline programming quiz. In 30 minutes I had to write code in C++ to counts the number of times each unique word appears in a...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.