|
You should restrict access as much as possible. But if it's not possible to restrict it anymore, than a global object is ok, I'd say.
Of course it's also possible to pass the object to every constructor or function as a parameter.. but this can get really complicated, especially if you notice that you need such an object after already having some code.
|
|
|
|
|
I suggest using a dependecy injection container (Unity Application Block, Castle's Windsor Kernel, Spring.NET). Then you have only one single global variable, the container itself.
All other global variables will make unit testing, decoupling of components and maintenance a great bit more difficult.
Happy coding
Urs
-^-^-^-^-^-^-^-
no risk no funk
|
|
|
|
|
An object-oriented approach to obtaining the functionality of global variables is the Singleton design pattern. http://en.wikipedia.org/wiki/Singleton_pattern[^]
You can even put multiple variables into your Singleton that need global access.
|
|
|
|
|
Hi All,
If I have two lists and one is a subset of the 'main' list what's the quickest/best way to sort the sub list into the same order as the source main list?
Cheers,
|
|
|
|
|
One way could be that you create Comparison(T) method (or create comparer class and implemet IComparer) and use that for sub lists Sort parameter. Instead of comparing which one of the attributes is greater, use your main list to make the decision.
The need to optimize rises from a bad design.
My articles[ ^]
|
|
|
|
|
Please Help me, how can i build Software like "Privacy Guard"(its new name is "Hide Your IP Address / Version 1.0") in "C#"
|
|
|
|
|
It's like eating an elephant. You have to do it in small pieces.
|
|
|
|
|
First, catch an elephant...
|
|
|
|
|
Damn, I knew I was missing something important...
The need to optimize rises from a bad design.
My articles[ ^]
|
|
|
|
|
You need to plan this first.. You have to decide if you want to catch an asian or an african elephant. Then you have to decide which elephant-gun you want to buy. And finally, you have to choose the airline to fly to Asia/Africa.
|
|
|
|
|
African elephants are the only way to go.
I can't take the elephant home on a plane; so I'll have to take a boat.
There are plenty of gently-used elephant guns lying around Africa; I'll pick one (or two) up when I get there; that should make getting through customs easier as well.
|
|
|
|
|
He´s to heavy you will crash or sink! just kill the african elephant!!!
The meat is worthless so take just the ivory, smugle it, you can sell it for a good price in europe.
Take the money and hire a good programmer to do any software you want!!!
nelsonpaixao@yahoo.com.br
trying to help & get help
|
|
|
|
|
You can't hide your IP address. It's that simple. If you changed the source address of outbound packets, the server you connect to won't know where to send the return packets back to. That's why you can't do this locally on your PC.
Now, if you had a proxy server, you're automatically hiding your true IP address because you're going through a "man-in-the-middle" proxy server that is making requests for you and returns the result to you. That proxy will always know what your true IP address is. The target server that you are ultimately contacting won't know your IP address, but instead WILL know the IP address of the proxy.
The only thing that's really hiding your IP is the trust in the proxy server that your IP address isn't being recorded in a database somewhere.
|
|
|
|
|
I Very Thankful to you for replying
If i have proxy server so what can i do???
|
|
|
|
|
Give it up. You've been completely missing all the concepts required to understand how thsi works for well over 6 months now. As you've been repeatedly told for months, you need to completely understand how and why TCP/IP works in order to do something like this.
|
|
|
|
|
Great reply, Dave, but what does that have to do with eating elephants?
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I don't eat elephants. My, now previous, job was to, single-handedly, push a pack of dead elephants up to the summit of Mount Everest. Ahh! Government contracts, you gotta love 'em...
|
|
|
|
|
User asked this in August. Bad subject title.
Blog link to be reinstated at a later date.
|
|
|
|
|
Well, if I were you, I'd sign up for a beginners course in network protocols.
|
|
|
|
|
Pete O'Hanlon wrote: beginners course in network protocols
A little English Refresher course would help as well. See his capitalization and sentence formations.
Vasudevan Deepak Kumar
Personal Homepage Tech Gossips
The woods are lovely, dark and deep,
But I have promises to keep,
And miles to go before I sleep,
And miles to go before I sleep!
|
|
|
|
|
Hi everyone, I'm developing an application that can control the mouse to do things. Now my app can force the mouse to move to any point and do left click or right click. Before I explain my problem about mouse scroll, I'd like to show my code to you.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Threading;
namespace SeniorProject
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Process[] p = Process.GetProcessesByName("winword");
if (p.Length > 0)
{
// Set focus on Microsoft Word program when user click button 1
SetForegroundWindow(p[0].MainWindowHandle);
Thread.Sleep(10);
}
Cursor.Position = new Point(100,200); // Bring pointer to (100,200)
const UInt32 MOUSEEVENTF_LEFTDOWN = 0x0002;
const UInt32 MOUSEEVENTF_LEFTUP = 0x0004;
const UInt32 MOUSEEVENTF_WHEEL = 0x0800;
UInt32 x = Convert.ToUInt32(Cursor.Position.X);
UInt32 y = Convert.ToUInt32(Cursor.Position.Y);
mouse_event(MOUSEEVENTF_WHEEL, x, y, 0x0010, new IntPtr());//Force the mouse to scroll
}
[DllImport("user32.dll")]
public static extern void mouse_event
(
UInt32 dwFlags, // motion and click options
UInt32 dx, // horizontal position or change
UInt32 dy, // vertical position or change
UInt32 dwData, // wheel movement
IntPtr dwExtraInfo // application-defined information
);
}
}
You see "0x0010" in the function mouse_event, right? The problem is that I cannot force the mouse to scroll down no matter what number I use, it will always scroll up. If I use greater number such as 0x0200 it will scroll up faster than less number such as 0x0010 but I really want it to scroll down T_T. So if anyone know how to make the mouse scroll down, please tell me and I'll really appreciate your help. Thanks a lot.
|
|
|
|
|
Check out this page[^] on pinvoke.net. Part way down there's a 'fixed' version of the function declaration that take ints rather than uints. Sending a negative value (after changing the function) should have the desired effect.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
Thank you very much Dave,now I can scroll it down according to your suggestion.
I changed UInt32 into int so I could assign the negative value to dwData and then the mouse finally scroll down. Thanks again Dave ^^
|
|
|
|
|
No problem
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
Hello friends,
I'm using VS2005 (.Net Framework 2.0). I have a few problems with the Windows Form controls. First, I've searched and searched, but couldn't find a horizontal separator control, like the one we see in the File Properties dialog box, in the Windows Form Controls library. Is there a way to add such a control to my forms or I have to derive a new class?
Second, the textbox control doesn't support transparent background. I've searched the Codeproject articles, but they all suggest long and complex method for the purpose. If someone can please suggest a sweet and simple solution, I'd be very grateful. I'm developing a new application and deriving new classes just to implement a new UI element is a time-consuming and complex affair.
Many thanks in advance.
modified on Saturday, October 25, 2008 8:56 AM
|
|
|
|