|
You're welcome.
Matt U. wrote: "Artists" is an entirely separate "List" object in an entirely different form's class file.
I can't judge that, having seen only a fraction of the code.
FYI: if you have say recordLabel.Artists=Artists; then that still is one and the same list, all the statement does is store a reference to an existing list; so if you then add/delete/modify an item in Artists, you will notice the same change in recordLabel.Artists, and vice versa.
Matt U. wrote: the application has taken a different path
I suggest you make it a habit to change the name of a method (or class) when its purpose in life changes; keep identifier names always as informative and as accurate as is reasonably feasible. And when you can't catch the functionality of a method in its name, add a little comment on top of it, explaining what the method does, using the domain or user terminology (and not the details of the code).
|
|
|
|
|
Right, I fully understand. I do have one more question. How would I go about making the 'RecordLabel recordLabel;' object (which is currently in the 'MainForm' class) accessible throughout the entire application? I currently create a new 'List<artist> Artists' in the 'ArtistsForm' class, for example. I then set it when the data file is loaded (there are other times, too) by "artistsForm.Artists = recordLabel.Artists". But wouldn't this cause the application's memory usage to go up?
BTW, I'm reading up on using 'Dictionary' now. But are there any situations in which a 'Dictionary' would NOT be the best solution?
|
|
|
|
|
Hi,
1.
string a="31232435342452";
string b=a;
string c=b;
looks like it has three strings; in reality only one piece of text is stored somewhere, and its memory address is stored inside the objects a, b, and c. So the memory penalty for copying objects is very limited.
2.
Passing objects around seems to be a difficult concept for the OO novice.
If there ever is only one list of artists, you might make it a public static member of class Artist, so it could get accessed by everyone from everywhere using Artist.artists
However that is not the best way, as sooner or later you'll want two or more lists of artists.
One normally does create the list once, then pass it on to other interested objects, either through a constructor parameter, a method parameter, or by setting a property to that effect.
3.
Dictionaries are fine; their one limitation is all key values must be unique and non-null. Which sounds fine for artists with a UniqueID field.
|
|
|
|
|
Okay, cool. So I think I'll be on the right path once I change some of the code. You're right about the Dictionary keys being fine. In the code all "Artist" objects must have an ID, and it's generated in a way that makes it unique every time. That is, unless the user changes the system date/time to match an existing ID. :-P But there's no point.
|
|
|
|
|
Hello all,
I have an image with black pixels, I want to convert all the pixels to a certain color. How can I do that without setting all the pixels that is black to that color ?
I thought something with the color matrix gdi supports.
Thanks, berlus.
|
|
|
|
|
Get the Location Color of Pixal then Create a image according to Your Requirement. If you can think then I Can.
|
|
|
|
|
Might someone recommend a good Winsock library that makes client/server communication easy? Commercial OK.
Although I'm sure the ones here on CodeProject are good, my project requires something bulletproof.
Anyone familiar with a good one?
I'm looking for something that has an API similar to that of a message-oriented named-pipe, but that, of course, works across the internet.
MSMQ is a bit more robust than I had in mind. I just want to pass messages between applications running on different machines separated by the internet.
It has to make asynchronous comm easy.modified on Thursday, March 4, 2010 4:29 PM
|
|
|
|
|
Richard,
It really depends on what you want to do. The company I currently work for uses TcpClient and TcpListener to communicate data between our apps. There are plenty of examples on this site for that. Search for "IPC" Inter process Communications.
If you are really looking for bullet proof, I would probably recommend MSMQ[^] (Microsoft Message Queue). If you're not a Microsoft fan, then try IBM WebSphere MQ[^] They are supposed to guarantee messages delivery and both are already proven.
I have had personal experience with MSMQ and it was simple to implement in C#.
Good luck and I hope I helped!
Hogan
|
|
|
|
|
Thanks for your response. I've clarified my question with details of what I'm looking for.
|
|
|
|
|
A quick search[^] shows how easy and safe it is for MSMQ over the internet.
Hogan
|
|
|
|
|
Thanks again!
I was originally under the impression that MSMQ was some enterprise thing that you had to purchase separately and run on a dedicated server.
But now it looks like it's entirely contained within .NET, and will work peer-to-peer.
Is this true?
|
|
|
|
|
Sorry I didn't explain that better. Unfortunately it isn't part of the .NET framework. MSMQ is its own install.[^] Once it is set up, it runs great. But as far as I know, you have to set it up on each machine manually. Good luck with your project!
Hogan
|
|
|
|
|
Why not go straight to the source?[^]
It is easy to use and works well.
The System.Net.Sockets.TcpClient class in C# uses it fairly well and provides a real nice interface for both synchronous and asynchronous calls.
|
|
|
|
|
hello to all
i m interested in C# coding devlopment but right now i have a problem that i want to show file names of a directory one by one in a lable when i press a button. can any anybody interested to help me in this way.............
tahnks
|
|
|
|
|
System.IO.Directory.GetFiles("Some Path");
|
|
|
|
|
hello,
I try to do a loop in my service and in the running of the start service he not give me to run the service beacuse i have my loop..
someone know what to do?
Thank You,Thank You!!
|
|
|
|
|
You have to move your actual service code to a background thread.
In the services OnStart handler, traditionally, you're expected to start your services worker on a seperate thread. Your code then can return control back to the Service Manager that told your code to start, thereby avoiding the timeout problem you're probably seeing.
|
|
|
|
|
Can anybody tell me what is wrong with my logic in the following code? I am trying to get a string array to take the names of projects entered one at a time from a text box. I have to be able to add to, delete from and sort the list alphabetically.
I can't use SQL because most of the time this program will be used offline.
When I build and run it I am getting no errors until the button click after entering the text in the box.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Collections;
namespace Construction_Survey_Layout
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public int PN;
private void btnNew_Click(object sender, EventArgs e)
{
ArrayList Projects = new ArrayList();
Projects[PN] = textBoxAddNew.ToString();
Projects.Add(Projects[PN]);
textBoxAddNew.Clear();
Projects.Sort();
for(int ctr = 0; ctr <= PN; ctr++)
{
listBox1.Items.Add(Projects[ctr]);
}
PN++;
}
}
}
|
|
|
|
|
Darrall wrote: ArrayList Projects = new ArrayList();
Why do you do that on each click?
|
|
|
|
|
Sorry...I wasn't very explicit there. This program is for a construction survey program. Somebody first using this program would enter the name of the first project he worked on. Then as he went along each time he got a project he would add a new one so in reality the click event occurs once every few weeks but the data has to remain in the program.
|
|
|
|
|
Yes, but why create a new empty list each time?
|
|
|
|
|
Yes I caught that...Thanks
|
|
|
|
|
Darrall wrote: Projects[PN] = textBoxAddNew.ToString();
The entry at PN doesn't exist yet, since Projects has a count of 0 at that line.
Darrall wrote: Projects.Add(Projects[PN]);
This line almost never makes any sense (it can, sometimes). Even less in this case, since Projects[PN] can not exist (Projects still has a count of 0)
Just do Projects.Add(something) somewhere and forget about PN..?
And don't forget to add the rest of the things that you want in there - the way it is now you'd have just 1 item all the time (so sorting it does nothing)
Darrall wrote: ctr <= PN
Why not just ctr < Projects.Count ?
Then you could eliminate that confusing PN entirely
And please use a List<string>
|
|
|
|
|
Thanks for your answer
|
|
|
|
|
There are a number of things wrong here, not just that you get an error.
I assume you are new to C#?
Darrall wrote: // PN is the index. I didn't set it to 0 because I want it to retain it's value
// It is at 0 the first time run.
public int PN;
It will retain it's value anyway. Setting the inital vaule with
public int PN = 0; makes no difference at all. Each time you construct a Form1 object you will get a new PN, that starts at zero. If you want one PN that is shared by all instances of Form1, then make it static:
public static int PN = 0;
Don't declare fields as public unless you need them accessable outside the class, use private. You can easily create a public property which accesses teh field, which has the advantage that you can provide a getter only, and it becomes readonly to the outside world.
Darrall wrote: ArrayList Projects = new ArrayList();
This creates Projects as local to the btnNew_Click method - i.e. it is discarded when you exit. Since you keep the PN as part of the class, I would suggest this should be also.
Darrall wrote: // The error was directed at PN here.
Projects[PN] = textBoxAddNew.ToString();
Projects.Add(Projects[PN]);
textBoxAddNew.ToString() does not give you the data typed into the textbox - textBoxAddNew.Text does.
Projects[PN} does not exist. If it did, then these two statements would try to add the same string twice.
That is why you get the error message - you are trying to access an element that does not exist.
Don't use an ArrayList - use a List<String> instead - it restricts what you can add to the list to just strings (arrayList will take Strings, ints, doubles, anything).
Why do you bother with PN when the ArrayList and List both have a Count which is going to be exactly the same as PN anyway?
Why sort the Projects? Just set the Sorted property of your ListBox.
Why are you adding all the Projects strings to the List box each time?
Better way to do all this:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private List<string> Projects = new List<String>();
private void btnNew_Click(object sender, EventArgs e)
{
Projects.Add(textBoxAddNew.Text);
listBox1.Items.Add(textBoxAddNew.Text);
textBoxAddNew.Text = "";
}
}
[edit]Forgot the "encode "<" .. option when pasting. Again. Damnit![/edit]You should never use standby on an elephant. It always crashes when you lift the ears. - Mark Wallace
C/C++ (I dont see a huge difference between them, and the 'benefits' of C++ are questionable, who needs inheritance when you have copy and paste) - fat_boy
modified on Thursday, March 4, 2010 11:45 AM
|
|
|
|