|
Hiya
What exactly is the get and set used for?? I have looked in a number of books but still don't understand what they are for..
Thanks.
|
|
|
|
|
look for accessors
(Properties in VB)
Free your mind...
|
|
|
|
|
The quick and easy is as follows. If you want to control assignment of values to an object you use a private/public variable system. The object accesses the data via the private variable and the public variable is how other objects interact with the object.
Example:
private string username = "";
public string Username
{
get
{
return username;
}
set
{
if !(socket.Connected) username = value;
}
}
This only allows another object to change the username of the object when "socket.Connected" is false. If you didn't use public/private with get/set you would not be able to control the value assignment and other objects would always be able to change the value and set it to whatever they want.
|
|
|
|
|
Does anyone know why PageScale doesn't work while double buffering?
Gary Kirkham
A working Program is one that has only unobserved bugs
I thought I wanted a career, turns out I just wanted paychecks
|
|
|
|
|
Hi,
My app runs a DOS program as a process. Most of the time, given the right command line arguments, the DOS process runs by itself without needing any user intervention, but there is a certain situation that can arise where it expects the user to respond "y" or "n" to a question. Is there any way to detect that the process is waiting for this user input?
Thanks
|
|
|
|
|
Is it really a DOS program, or is it a Win32 console-mode program?
There are probably only two cases:
1) You need to be parsing the output of the program in order to decide whether to respond with a 'y' or an 'n'. In that case, you should be reading the program's standard output and you will see when the question appears.
2) You don't care are are always going to give the same answer. In this case, just go ahead and stuff a 'y' or 'n' into the standard input and it will be buffered for the application to read.
The less likely options where you might need something more complicated involve the application intentionally flushing buffers and such, but don't go there until you've considered the options above.
--
-Blake (com/bcdev/blake)
|
|
|
|
|
Blake Coverett wrote:
1) You need to be parsing the output of the program in order to decide whether to respond with a 'y' or an 'n'. In that case, you should be reading the program's standard output and you will see when the question appears.
Well, that's want I'm doing at the moment, but I was wondering if there was a more flexible and fool-proof way of doing things. Right now I'm comparing strings coming out of the stdout (actually, it's the stderr) to a string I know will appear if it decides to ask this question. Then my program will pop up a yes/no message box and, depending on the users response, sends either a 'y' or 'n' to the stdin. The problem is, what if that string changes in the DOS program I'm running (I didn't write it), and what if there are other situations that might need a users response (again, I didn't write it).
|
|
|
|
|
The question of "what if there are other situations that might need a users response" is exactly why you should stick to parsing the output. At least then, if the output doesn't parse you'll know you have an unexpected situation and can abort. If you just assume the first time it stops for input it is asking that y/n question you might end up stuffing a 'y' into a completely different question by mistake.
--
-Blake (com/bcdev/blake)
|
|
|
|
|
True, but only if exactly the same line that I'm using to catch the question I expect to see occurs again, but in a different context (and, in fact, there are two different lines I try to catch, so both lines would have to appear to trick my code). Otherwise, it'll just hang up waiting user input that never comes, although the stderr is sent to a window so the user ought to be able to see that something abnormal has happen and can click on the cancel button. I guess I'll just have to settle for that. I guess I could set a timer and if there is nothing on the stdout or the stderr for some period of time, I could warn the user and give them the option of sending something to the stdin. The problem with that is that the program I'm running can pause and seemingly do nothing for several seconds even in normal operation.
|
|
|
|
|
Hello All,
I am developing an application that should communicate with a COM component. The COM component is developed in VC++.
The COM component is successfully created after
Activator.CreateInstance(..) call, but getting destroyed immediately.
Can you help me out in solving this issue.
Thanks in advance.
Mahesh
|
|
|
|
|
If the variable that the return value of Activator.CreateInstance falls out of scope, the COM object will be (eventually, sometimes sooner) disposed (cleaned-up). Have you set the return value to a field in a class to keep a reference of it?
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Thanks for your response.
I have assigned the return value(object) to a member variable of the class.
Still the instance is getting closed immediately.
|
|
|
|
|
Why don't you import the tlb? (tlbimp.exe)
If your C# app has the [STAThread] attribute in its entry point, make sure to have an appropriate COM object (registry lookup under the InprocServer32 or LocalServer32 key, ThreadingModel value).
A few suggestions : change the attribute to [MTAThread] (read the docs), create a new thread and create the COM instance from there.
Otherwise, if you can't afford a simple tlbimp, then I suggest to have a c proxy that would start the com object for you.
RSS feed
|
|
|
|
|
Hi,
How can I extend an array like int[] or create a dynamic length's int[]? For example:
int[] a = new int[10];<br />
<br />
for ( int i = 0; i < 10; i ++ ) {<br />
a[i] = i;<br />
}
Now I want a to be int[11] and a[10] = 10, how can I do it?
Thanks.
|
|
|
|
|
|
|
I was able to add the Microsoft Web Browser control in Visual Studio .NET 2003, but alot of the properties are in grey so I can't point url to the control, please tell me exact how I can add a url to the Microsoft Web Browser control I added on my C# windows form application, what code I write? I'm total noob, I only know how to use the IDE but I don't know the C# language syntax, please help X_x;;
http://www.hentaitheme.com
Free Public Ragnarok Online Game Server
|
|
|
|
|
Hi .. just add the Web Browser Control to you application, then use
object flags = 0;
object targetFrame = String.Empty;
object postData = String.Empty;
object headers = String.Empty;
this.axWebBrowser1.Navigate("http://www.ebay.com/", ref flags, ref targetFrame, ref postData, ref headers);
But if you want more informations there are some WebBrowser Source Codes here on Codeproject! That you are a beginner is no problem, but learning is to understanding If you want to program such things you have to learn c#
Greets
Matthias
|
|
|
|
|
you can't just add these codes anywhere right?
object flags = 0;
object targetFrame = String.Empty;
object postData = String.Empty;
object headers = String.Empty;
this.axWebBrowser1.Navigate("http://www.ebay.com/", ref flags, ref targetFrame, ref postData, ref headers);
I mean you have to add those code within something{ } right? but where? X_x;
http://www.hentaitheme.com
Free Public Ragnarok Online Game Server
|
|
|
|
|
Take a look at any of the articles for the basics of c#.
|
|
|
|
|
<br />
public class LogClass <br />
{<br />
private TextBoxBase outputWin = null;<br />
<br />
public LogClass(TextBoxBase win)<br />
{<br />
outputWin = win;<br />
}<br />
<br />
public void ShowMessage(string message)<br />
{<br />
string s = System.DateTime.Now.ToString() + ": " + message + "\r\n";<br />
lock ( this ) <br />
{<br />
if ( outputWin != null ) <br />
{<br />
if ( s.Length + outputWin.TextLength > outputWin.MaxLength ) <br />
{<br />
outputWin.Text = "";<br />
}<br />
outputWin.Text += s;<br />
}<br />
}<br />
}<br />
}<br />
<br />
<br />
public MyClass<br />
{<br />
private System.Windows.Forms.TextBox logBox;<br />
<br />
private void DoSomething()<br />
{<br />
log.ShowMessage("thread running" );<br />
}<br />
<br />
private void button3_Click(object sender, System.EventArgs e)<br />
{<br />
log.ShowMessage( "start test" );<br />
Thread[] t = new Thread[10];<br />
int i = 0;<br />
for ( i = 0; i < 10; i ++ )<br />
{<br />
t[i] = new Thread(new ThreadStart(this.DoSomething));<br />
t[i].Start();<br />
Thread.Sleep(100);<br />
}<br />
<br />
log.ShowMessage( "end test" );<br />
}<br />
}<br />
<br />
public MyClass()<br />
{<br />
log = new LogClass( logBox);<br />
}<br />
<br />
}
My code gets stuck at the LogClass.ShowMessage(). Anybody knows why?
Thanks in advance!
|
|
|
|
|
Hi!
I want to get all Logical Drives, the Directories and the Files of a Server in my Network.
I know how to view all this Stuff on my local Computer (Directory class, File class). But how should i view it on a other Computer in the Net? I tried to do this with the same classes but it didn't work.
Does anyone have an idea?
wg
Christoph Marchgraber
|
|
|
|
|
It's an ugly object model and it overloads the term 'managed' in a bad way for people who started with the CLR, but the WMI based classes in the System.Management namespace are what you are looking for.
--
-Blake (com/bcdev/blake)
|
|
|
|
|
Hey,
I created a custom object. For the public properties I used
///
/// xxx
///
and i used also the [description]- attribute.
I build a dll and referenced to it from another application.
The control works fine, but there is no intellisence and no description in the propertybox.
What did I do wrong? In which XML-file I will find al this comments?
Thanks
Bene
|
|
|
|
|
Description attributes should show up in the VS designer automatically. For xml comments, you need to tell Visual Studio to create an xml file (right click your project->Properties->Configuration Properties->XML Documentation file)
The graveyards are filled with indispensible men.
|
|
|
|