|
Try this :
....
FPRec = new csFPRec();
FPRec.uiPGN = 0x5678;
FPRec.uiFrameCtr = 0x02;
...
You added the same instance FPRec twice
|
|
|
|
|
Thanks Richard - that has fixed the records being the same on the hashtable.
Can you see what I am doing wrong in getting the records off the hashtable?
Many thanks, Bruce
|
|
|
|
|
Woops! - Wrong thanks. Thanks Estys.
Chers Bruce
|
|
|
|
|
...
pgnobj = HT[(UInt32)0x1234];
...
The basic Comparer is Object.Equals()
Your key value was converted (cast) to System.Int32 which does NOT equal UInt32 (I suspect)
modified on Wednesday, December 16, 2009 9:21 AM
|
|
|
|
|
Got It!
Many thanks Estys. Solved it. Really appreciate your help.
Cheers Bruce
|
|
|
|
|
Hello,
how is it possible to communicate with a Silverlight-App in a WebBrowser-Control in WinForms?
Is there also a possibility to use the same Classes (of course both need to have the same Interfaces)?
So can i return a class from the Silverlight-App into my WinForms-App? And that without JSON and JavaScript and blah?
Many thanks
|
|
|
|
|
Hi all,
There is a small problem with me, so thought to share it with all of you, thought i will find any idea, I have a window application created with C#, i want to create the functionality of taking backup and restoration of application data, i found some threads on google which r showing the process of taking backup from the database, my need is to create a backup file of application database n again restore it when needed
waiting for positive reply
thanks in advance for all your responses
Regards
Narendra Singh
(Jindal Tech Ventures)
modified on Friday, December 18, 2009 7:46 AM
|
|
|
|
|
So what's the problem?
If application uses local file, just copy to different folder
|
|
|
|
|
thats the question,
HOW
Regards
Narendra Singh
(Jindal Tech Ventures)
|
|
|
|
|
|
Thanks saksida for ur helpful reply
Regards
Narendra Singh
(Jindal Tech Ventures)
|
|
|
|
|
and I have little idea how to implement it...
I created a code folder, and a DeviceData class in it, with a constructor that (hopefully) constructs a local device of a variable type when it's instantiated. I don't actually know if it's possible to pass an object to a constructor and cast it to a specific object type based upon a Type parameter, but the compiler doesn't whine about it. I assume it's working. But I could be wrong...
My thinking is to add to the DeviceData class member functions that handle the Add, Edit, Delete, and View functions that encapsulate all the nasty database communication details so the rest of my program doesn't have to deal with them. I just want to pass an object of one of 5 types to this code block, specify what I want it to do with it, and forget it.
The devil is always in the details, though, and when I try to buld a function to add a new device to the database, the IDE snivels about an Identifier being required as the Add function parameter. I know that doesn't help much, so here's the constructor:
public DeviceData(int Type, object Device)
{
switch (Type)
{
case 1:
Recloser dev = new Recloser();
dev = (Recloser)Device;
break;
case 2:
break;
case 3:
break;
case 4:
break;
case 5:
break;
default:
break;
}
}
I could be completely out to lunch, but I think that creates a member variable called dev of a type defined by the object type passed to it. At least, I hope so, and VS doesn't generate any nasty errors when I build the solution. Unfortunately, when I try to actually use the variable, things get ugly:
public int GetDevice(dev)
{
return 0;
}
At this point, the compiler complains that I haven't provided an identifier, and I don't know why. My intent is to instantiate the DeviceData object by passing the constructor a specific object that has been populated using a Form in another part of the program. My thinking is that this should create an instance variable, called dev, that can be filled with the field data from the passed object. The next step would be to query the database to populate the fields, then return the object to the calling Form module. I haven't a clue at this point why I'm receiving this message, though, and would appreciate any input.
"A Journey of a Thousand Rest Stops Begins with a Single Movement"
|
|
|
|
|
public DeviceData(int Type, object Device)
Where is return Type? This is function and if you do not want to have return type, use void
Edit: To check object for type use:
if (device is Recloser)
dev = (Recloser)Device;
This (int Type) shroud be avoided, you can make a mistake, and it the code can become unreadable
|
|
|
|
|
Saksida Bojan wrote: Where is return Type? This is function and if you do not want to have return type, use void
It's probably a constructor.
|
|
|
|
|
Exactly.
"A Journey of a Thousand Rest Stops Begins with a Single Movement"
|
|
|
|
|
The IDE is supposed to snivel at the switch-block. I don't think you can put a declaration in the case-blocks, unless you enclose the entire case block in {}. So this:
case 5:
LTC dev = new LTC();
dev = (LTC)Device;
break;
becomes this:
case 5:
{
LTC dev = new LTC();
dev = (LTC)Device;
break;
}
Roger Wright wrote: public int GetDevice(dev)
I don't know if this is a proof of concept, but I think you need to provide a type, or remove the parameter and use the local variable instead.
|
|
|
|
|
both syntax of Switch case are valid
The problem lies in decleration "LTC dev = new LTC(); " is declared within case block. It doesn't exists outside
|
|
|
|
|
Hmm. Perhaps an unusual approach you describe.
Why, for starters do you need an integer defining the type? The actual object itself has type which we can query.
The different type 'dev' variables you create are only going to have local scope (ie last as long as the case part). And, from memory, I don't think its going to allow you redeclare a variable multiple times in a single switch. Normally, dev would be some sort of member variable.
This:
Recloser dev = new Recloser();
dev = (Recloser)Device;
makes no sense. You'd use:
Recloser dev = (Recloser)Device;
Perhaps what you want is multiple constructors, each taking a different subclass of device?
public DeviceData(Recloser device)
{
dev = device;
}
etc.
Another question - why have a single data access class which handles all these different 'devices' - why not have one per class? That would make life quite a bit simpler as you won't have to be continually determining what device you've got before taking actions.
All very vague I'm afraid.
Regards,
Rob Philpott.
|
|
|
|
|
Excellent points - Thanks!
It was, necessarily, very late when I was working on this, so my own reasoning might not be at its best.
The idea of using a single class was to save on mostly redundant code, but this morning I can think of several better ways to do this. I totally forgot about the mechanism for determining the type of device. Looking at it now, I can see my own bias for procedural programming in the approach... gotta work on that mindset.
"A Journey of a Thousand Rest Stops Begins with a Single Movement"
|
|
|
|
|
Firstly, have you considered existing technologies to handle DAL. NHibernate is very good and.NET's own LINQ framework has both the Entity Framework and LINQ to SQL that could all make your task easier?
If you don't want, or can't, go down a ORM route using the technologies above, the task becomes much harder. One common route is to generate the code that handles CRUD operations in the DAL for each class. I've had to implemented a "Lite / Dummies'" version of ORM, decorating classes with table mappings attributes and properties to be persisted with column mapping attirbutes (column name, type, any conversion functions and whether the column takes part in the table's PK), the CRUD databse operations can then be performed by one class which inspects the object passed to it by relefection.
Things that you might run up against, depending upon your implemenation:
- Relations between tables e.g. delete from table A, but this breaks a FK constraint to table B, or you have an property that is itself a of a type you persit: you need to persist in the correct order and make sure that the owner object has a PK /FK relationship to the child object, and the OK of the child object must be defined.
- Null handling
- Default Value handling
- Defining primary keys on tables
- Conversion from object property type to DB cloumn types and exceptional cases were the standard conversion is insufficient
- Inheritence Problems (how do you represent an inheritance hierearchy in the DB, Table per sublcass, table per hierarchy etc).
All these problems are soluable (with varying degrees of sucess and complexity), and it's important not to try and solve them up front, but be aware you might come across them. Unless you are doing this as a learning exercise (which is a good thing to do) I'd consider the Entity Framework or NHibernate.
Good luck!
CCC solved so far: 2 (including a Hard One!)
37!?!! - Randall, Clerks
|
|
|
|
|
This definitely is a learning experience, despite the fact that the app will be useful at work. Most of the considerations you mention are new to me, and probably aren't significant in so simple an app - managing history records for 5 or 6 types of equipment. It's the sort of thing one could do easily as a simple web page using ADO, but I'm using this as a tool to become more familiar with C#.
Thanks for the suggestions!
"A Journey of a Thousand Rest Stops Begins with a Single Movement"
|
|
|
|
|
Roger, I'm only 300 miles from you and I need work (and a trip to Laughlin), might I be of assistance?
P.S. I should have mentioned also, I'll be in Sedona for part of next week, that's half-way already.
|
|
|
|
|
Advertising?
CCC solved so far: 2 (including a Hard One!)
37!?!! - Randall, Clerks
|
|
|
|
|
It's the best lead I've had in weeks.
|
|
|
|
|
We do need to get together one of these days, but a working trip would interfere with our drinking. After all, we're practically neighbors. I wish I could break away for a day to see you in Sedona, since it's just around the corner, but I'm swamped at work for a while. If the company ever decides to hire a real programmer, I'll definitely contact you. In the meantime, they expect me to do this with a spreadsheet - which is completely impractical - hence my effort to create a reasonable facsimile of a working data management program in my free time at home.
"A Journey of a Thousand Rest Stops Begins with a Single Movement"
|
|
|
|
|