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

Is Object Datatype right?

48
Hi there,

I've two projects - one is an exe & the other is a dll. I add a reference of the dll project to the exe so that it can access dll project's types. Now in my dll project I've code which requires reference to the exe project; this is not possible as it would result in circular dependency. Hence all I'm doing is I'm passing exe's type say for example the MDIForm of the exe project to the dll project with datatype being Object. Now I can happily access all the MDIForm's members in the dll project.

My question:
  1. Is it okay to declare the MDIForm as Object datatype in the dll project?
  2. The disadvantage of using the Object datatype is that I cannot see its members while coding i.e. intellisense doesn't shows the MDIForm's members. Is there a way to typecast it to the exact type?

Thanks,
Aads
May 12 '09 #1
15 1315
balame2004
142 100+
There is a way to typecase your MDI form that you have passed as object.

You just mention the object with the type of Form. So intellisense will show the members of the MDI form object.

Eg:
C#:
string formName=((Form)mdiFormObj).Name;
May 12 '09 #2
Aads
48
Thanks for your quick reply.

If I typecast it to Form, It would only show the standard form members not the one which I have written. For example: I might have written a public function by name AddTwoNumbers, which would not appear in the intellisense as it is not a member of a standard form but the member of my class. I want this member to be displayed in the intellisense. In fact it could be any user defined class for that matter.

Hope now its clear.

Thanks,
Aads
May 12 '09 #3
Plater
7,872 Expert 4TB
Perhaps you should consider making all of your custom functions declared as an interface(or something) and keep that in the DLL.
So you can reference the functions that way?
May 12 '09 #4
madankarmukta
308 256MB
@Aads
Could you please once chec for the accessibilityof the members which you are calling..?

Are the member , you are expecting to be there in intellisence list ,accessible in
called environment ?

Thanks!
May 13 '09 #5
Aads
48
@Plater
That means it will be available to me superficially.. Having said that is there any way that I can typecast it to my exact type?

Thanks,
Aads
May 13 '09 #6
Aads
48
@madankarmukta
Yeah the accessibility of my methods are all okay i.e. they are all public.Since I'm not able to typecast it to the exact type & instead using Object datatype as a solution, I'm not able to see the members in the intellisense.

Thanks,
Aads
May 13 '09 #7
Plater
7,872 Expert 4TB
I'm pretty sure my terminology is wrong, as I haven't actually done this, but I think it can be done.
What I was thinking was that all your custom functions where in an interface "myIFace" say that is stored in your DLL. Your EXE program has a form that implements that interface. Now your EXE side works as normal.
Then your DLL could be told to use myIFace instead of Object as the datatype, and all your custom functions should appear in the intelisense?
May 13 '09 #8
Frinavale
9,735 Expert Mod 8TB
@Aads
Perhaps you should consider redesigning your application.

A DLL (a class library) is supposed to be a library of classes that can be used in other applications. It should not be concerned with the code that is using it.

Why does your DLL need to reference something in the application (the EXE) that is using it?

Does it just need a reference to a method?
In that case consider using Delegates (or Function Pointers) so that the class within the DLL can reference the method.

What does the DLL have to reference and Why?
May 13 '09 #9
Aads
48
@Frinavale
Well that's a good question. You are absolutely right that a dll project should be independent of the exe project.

Well I'm working on a mechanical project containing intensive mathematical calculations - the UI is just an exe containing MDI form & the other dll projects contains only mathematical calculations. I have a ToolStripProgressBar control on the MDI form of the exe project which needs to be updated from the dll project to report the progress to the user as the calculation progresses. Hence I need to access the exe project from the dll project.

Secondly there are three language options in the MDI form namely French, English & German. Based on the language selected my dll project's mathematical sub routines vary slightly. Again in this case, I need to access the exe project's members.

Hope its clear now.

By the way, could you please tell me how delegates can solve this problem?

Thanks,
Aads
May 13 '09 #10
Frinavale
9,735 Expert Mod 8TB
In your case you should probably look into using Events.

After a "milestone" has been reached in your math calculations you should raise an event indicate it's progress....

Your windows application will implement a method that handles this event and updates the progress bar :)

As for the cultural settings....you could create a Property for the class that's doing the calculation which can be set to indicate which calculation should be preformed....

Or you could look at using Globalization (I've never used this with a class library though so you'll have to look into this)
May 13 '09 #11
Aads
48
@Plater
That's great! Good logic! and guess what it worked! As you said, I declared an Interface in the dll project & then implemented the same in both exe project's MDI Form & in the classes of the dll project & then used the interface as the datatype instead of object. Now I can see the members in the intellisense. Cheers buddy I appreciate it.

Thanks,
Aads
May 13 '09 #12
Aads
48
@Frinavale
Thanks for your quick reply. Using Events is not a bad idea, however, I need to do bit of R & D on that.

Thanks,
Aads
May 13 '09 #13
Bassem
344 100+
No it isn't, I was addressing the same situation and I reached to events by my self .. I was glad for that. Now I'm glad again to see an expert recommend my solution.

Why don't you pass a value like an enum to which class in the DLL as an input to choose between your choices instead of reading it bottom from DLL up to the UI?

Thanks,
Bassem
May 14 '09 #14
Frinavale
9,735 Expert Mod 8TB
@Bassem
I really think that using Globalization would be even easier than passing this information....what ever culture the the code is being run under would determine the calculation to do.
May 14 '09 #15
Aads
48
@Bassem
Yeah that's not a bad idea either - I tried & it worked!

Thanks,
Aads
May 15 '09 #16

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

Similar topics

3
by: Phil Powell | last post by:
if (is_array($_POST)) { foreach ($this->getAssocSectionsObjArray($key, $dbAP) as $obj) { print_r($obj); print_r(" in array? "); print_r(in_array($obj, $result)); print_r("<P>"); if...
28
by: Daniel | last post by:
Hello =) I have an object which contains a method that should execute every x ms. I can use setInterval inside the object construct like this - self.setInterval('ObjectName.methodName()',...
2
by: Seb | last post by:
I am trying to initialize a const static object data member in a header file? The following code errs. class Object { public: virtual const char* ToString() { return "Object"; } virtual...
4
by: Otis Hunter | last post by:
I have been given an Access Database which contains a table that has an OLE object field that contains a Word document. That table contains hundreds of records. I would like to find out how I can...
0
by: Edwinah63 | last post by:
Hi guys, i am not new to vb6, but a mere tyro in vb.net what i want to do is the following open transaction build an ADODB command object using parameters execute it build another command...
5
by: Tim Frawley | last post by:
I created a .NET Com Class object for use in ASP reports to export database results directly to Excel. I have it all working just find but I cannot get the Excel process to go away after the job...
0
by: NDK | last post by:
Ok so I have an html page with an embedded excel object. I load some information into the object from a spreadsheet. (works perfectly) I would like to be able to change the background of a few...
8
by: =?Utf-8?B?UmF2aQ==?= | last post by:
Hi, I'm trying to pass values of different data-types to a web-service. I thought it would be easier to box these values and pass them as a System.object parameter, like public void...
32
by: Joe | last post by:
I am just starting to use Object Oriented PHP coding, and I am seeing quite often the following (this example taken from a wiki): $wakka =& new Wakka($wakkaConfig); What exactly is the =&, and...
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: 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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.