|
Sure,
this is class, which object`s are kept in array/arraylist:
[Serializable]<br />
public class DataGridRow<br />
{<br />
public int Time;<br />
public float Speed;<br />
<br />
public DataGridRow(int t, float s)<br />
{<br />
Time = t;<br />
Speed = s;<br />
}<br />
<br />
public DataGridRow()<br />
{<br />
<br />
}<br />
}
And this is part of other class, that performs serialization:
ArrayList RouteData = new ArrayList();<br />
<br />
(...)<br />
<br />
public void Serialize()<br />
{<br />
DataGridRow[] dgr = new DataGridRow[RouteData.Count];<br />
<br />
for (int i = 0; i < RouteData.Count; i++)<br />
{<br />
dgr[i] = (DataGridRow)RouteData[i];<br />
}<br />
<br />
XmlSerializer a = new XmlSerializer(dgr.GetType());<br />
<br />
StreamWriter sw = new StreamWriter(@"c:/aaa.txt");<br />
a.Serialize(sw, RouteData);<br />
}
Please let me know if I missed something
(I may send it to you if you like)
|
|
|
|
|
OK,
After going through the above code what i think is that
when u are serializing u have to fetch each item from the Arraylist and serialize each object which is of the class DataGridRow, and also
mention the class name in the XML Serializer constructor.
Also change the file type i.e. c:\aaa.xml
Try the above changes, if it works well and good
if not just repost the error that u get and send the project so that we can
debug and check what's going wrong.
Thanks & Regards,
Pramod
"Everyone is a genius at least once a year"
|
|
|
|
|
At begin I wanted to serialize the ArrayList with all elements included. Then some guy told me, that ArrayList objects can`t be serialized, but I`m sure that 1D arrays are. So thats why I copied all elements from ArrayList to Array of type DataGridRow. So I don`t think there is a must to serialize each object separately...
I changed file name to aaa.xml, still I get the same error.
Here you can download this whole project (112kb)
thank you very much for help
|
|
|
|
|
ok what i had done is
i created a class declared that serializable,
declared the properties and wrote a method which was used to
set values to the properties and also wrote the serialize method in the same class
and then in the serialize method i used this object to serialize.
The link that u have sent is blank and i could not find any project there.
Thanks & Regards,
Pramod
"Everyone is a genius at least once a year"
|
|
|
|
|
one important thing that u have forgot is
you have to declare the class as [XMLRoot "classname"]
and the properties as [XMLElement "name"]
try this
Thanks & Regards,
Pramod
"Everyone is a genius at least once a year"
|
|
|
|
|
one important thing that u have forgot is you have to declare the class as [XMLRoot "classname"] and the properties as [XMLElement "name"]
try this
Thanks & Regards,
Pramod
"Everyone is a genius at least once a year"
|
|
|
|
|
I added these attributes - still the same result
The link was correct, I tested it, but maybe server was down at the time you tried it. Nevertheless - this is the same project on another server:
Download (I tested it and it worked)
Or, if you still develope some problems with downloading, please supply mi with your @mail address
again, thank you very much for helping
|
|
|
|
|
HI YOYOSH,
i have downloaded the project and am working on that
will send u the working code soon
Thanks & Regards,
Pramod
"Everyone is a genius at least once a year"
|
|
|
|
|
i have made the neccessary changes and it's working fine
can u please send me your email address, so that i can send u the project.
Thanks & Regards,
Pramod
"Everyone is a genius at least once a year"
|
|
|
|
|
|
we generate .netmodule using command line as
csc /target:module /out:Form1.netmodule Form1.cs
csc /target:module /out:Form2.netmodule Form2.cs
is it possible to do the same task programatically if then how to do it
|
|
|
|
|
waheed awan wrote: is it possible to do the same task programatically if then how to do it
Yes. Simply start a new process via the System.Diagnostics.Process class. You can pass arguments to the Process's StartInfo property. Then call .Start() on the process to fire it off.
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Dumbest. Movie. Title. Evaaar.
The apostle Paul, modernly speaking: Epistles of Paul
Judah Himango
|
|
|
|
|
Hello,
my question would be too complicated if I used the real code, so I'll use a trivial substitutional example instead:
Let's have three separate objects - windows forms, invoked within one application: Form1, Form2, Form3. Form1 owns a method named AddOne() that adds number one to Form1's private field int Result and displays the result by assigning it to Form1's label1.Text property.
Forms Form2 and Form3 have both one button that, upon clicking, invokes Form1's method AddOne() and performs the above mentioned action in Form1.
Now how do the methods that are called upon the button click on either Form2 or Form3 access Form1's non-static AddOne() method?
Thanks for help,
Michal
|
|
|
|
|
you have to pass Form1 iteself onto the other forms through the constructors that create the other 2 forms.
Example:
Form1.css
Form2 frm2 = new Form2(Form1);
Form2.css
//Constructor
static void Form2(Form form1)
{
Form frm1 = form1;
InitializeComponents();
}
Then you can access the fields and methods in Form one by referencing them like so:
frm1.AddOne();
My code may not be exact because Ive never passed a form object but im sure that this would be a good starting point.
|
|
|
|
|
I'm not sure how safe it is, but this is what I'd do:
Pass in Form1 into Form2's and Form3's constructors, like this:
class bla : Form
{
private Form FORM1;
[...]
public bla(Form form1)
{
FORM1 = form1;
[...]
}
[...]
private someMethod()
{
FORM1.AddOne();
}
[...]
}
Since this is OOP we're talking about, you're just passing in the address of Form1 into the constructors. You just have to remember to instantiate Form1 before Form2 and Form3.
I've been known to do this, passing a form to different controls so that they can call the form's instance methods.
Like I said, I don't know how safe it is providing a form instance to the other constructors, but it should work (and I've never had any problems with that method).
Something else you could do is create a static member like this:
public static Form1 theForm;
And, when you instantiate Form1, set the static variable to the instance, like this:
Form1 f = new Form1();
thisClass.theForm = f;
Hope this helps!
-Daniel
Typing too fast fro my owngood
|
|
|
|
|
Thanks much both!
Passing the object itself to the other object to be able to invoke the first object's non-static method does really work.
Anyway, I was thinking about something more universal, like subscribing the AddOne() method as a client of the events of button clicks on the other forms. Would such a subscription be feasible between instantiated classes WITHOUT passing the entire object as a reference?
Something like this:
using System;
namespace ObjectCommunication
{
public delegate void MyEventHandler(string EventParams);
public class EntryClass
{
public event MyEventHandler MyEvent;
static void Main()
{
EntryClass MyEntryClass = new EntryClass();
EventDemoClass MyEventDemoClass = new EventDemoClass();
MyEntryClass.DoWork();
}
private void DoWork()
{
MyEvent += new MyEventHandler(EventClientMethod_1);
MyEvent += new MyEventHandler(EventClientMethod_2);
MyEvent("_event_parameters_");
}
private void EventClientMethod_1(string EventParams)
{
Console.WriteLine("MyEvent client 1 triggered with these params: " + EventParams);
}
private void EventClientMethod_2(string EventParams)
{
Console.WriteLine("MyEvent client 2 triggered with these params: " + EventParams);
}
}
public class EventDemoClass
{
public void EventClientMethod_3(string EventParams)
{
this.DoSomething(EventParams);
}
private void DoSomething(string Params)
{
Console.WriteLine("MyEvent client 3 triggered with these params: " + Params);
}
}
}
Here we would like to subscribe the EventClientMethod_3 method to MyEvent event in EntryClass. That would be more secure than passing the entire object as a reference in a constructor I think.
Thanks,
Michal
-- modified at 19:11 Monday 28th August, 2006
|
|
|
|
|
michal.kreslik wrote: That would be more secure than passing the entire object as a reference in a constructor I think.
Often times if you need some information from an object, but not the whole object, you use interfaces. Not only does this prevent access to the whole object, but it also abstracts away underlying implementation, which is really good for things like unit testing.
interface IObjectWithFoo
{
int Foo { get; }
}
class FooForm : Form, IObjectWithFoo
{
public int Foo
{
get { return bar; }
}
}
class Consumer : Form
{
public Consumer(IObjectWithFoo instance)
{
int val = instance.Foo;
}
}
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Dumbest. Movie. Title. Evaaar.
The apostle Paul, modernly speaking: Epistles of Paul
Judah Himango
|
|
|
|
|
Dear Friends,
Please email me some good final year project suggession. I know most of you have already design your final project. Please send me some good market oriented Project.
My email address is ali_fastian@yahoo.com
Please send me any suggession freely b/c it's very important 4 me. I am waiting for your replies....
Rgds,
aLi
|
|
|
|
|
You could write a little crawler that continually browses programming forums looking for email addresses.
When the crawler finds an address, it sends a message stating that it is a bad idea to post your email address openly in a forum because it attracts spam.
That's my suggestion.
--EricDV Sig---------
Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them.
- Laurence J. Peters
|
|
|
|
|
ali! this is your professor from university. i have a doubt you could make good student. i have a doubt you could make good person. now for shame you post your project on teh Cpian when i sexplicitly told you no! now you get dungeon blackened grade for your schooling on final project. you make me with your cheatings on the Cpians you monkey turd.
Sincelery yours, Computer Information conSciences Professor and grader, Sharada Ulhas
|
|
|
|
|
Dear Sir
I am not ask you to send me some codes
I only ask some suggession, what project i should select as a final year project.
Rgds,
aLi
|
|
|
|
|
Hi guys,
I want to extract some specific image metada from an .jpg file. I explored through the codeproject and msdn as well as google but found nothing (I mean not exactly nothing but only codeparts and info which are not I want).
Lets me explain in more detailed : I edit some image information from Photoshop (right-click on the image window header > file info > description tab).. After editing whenever I load an the image I want to see the description, title, author, keywords etc..
With the PropertyItem I can only view the description, author and creation time (other info doesn't worth for me).
So my question is how can I read AND write specific metada pieces ?
.:: Something is Wrong ::.
|
|
|
|
|
This might help: Retrieve detailed information of a File[^]
--EricDV Sig---------
Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them.
- Laurence J. Peters
|
|
|
|
|
hi,
I have an text file grouped into records that I need to be parsed into a object. The record is like :
H10000<cr> ( H from header of the record )
I1,name,age,sex (Information1)
C1,text... (Comment 1 for Information1)
....
Cn,text... (Comment n for Information1)
I2,name,age,sex (Information2)
C1,text... (Comment1 for Information2)
....
Cn,text... (Commentn for Information2)
...
In,name,age,sex (Information n)
C1,text... (Comment1 for Information n)
....
Cn,text... (Commentn for Information n)
E1 (End message)
There is a class for each Tag (H,I,C,E) and a Record class that is the superclass for the classes(H,I,C,E) . I need to parse this file and store the informations from the records into a object using generics. For the informations I must use a list. I also need the reverse operation : from object to write to file.
I realize that the code must be written by myself but I would appreciate some general help about how to create the object from file
thanks
|
|
|
|
|
Well seeing as it appears to be a CSV file you can read in the whole file line by line and split it to get various parameters.
while (stream.Peek() != -1)
{
string[] cells = stream.ReadLine().Split(',');
} Hope that gets you started.
As of how to accomplish this, have you ever tried Google?
|
|
|
|