Click here to Skip to main content
15,913,685 members
Home / Discussions / C#
   

C#

 
AnswerRe: Extending/Duplicating a Form Pin
Robert Rohde29-Oct-05 22:33
Robert Rohde29-Oct-05 22:33 
GeneralRe: Extending/Duplicating a Form Pin
MoustafaS30-Oct-05 16:27
MoustafaS30-Oct-05 16:27 
QuestionHow can I get info about which MenuItem that is clicked at runtime? Pin
M Shafaat29-Oct-05 14:11
M Shafaat29-Oct-05 14:11 
AnswerRe: How can I get info about which MenuItem that is clicked at runtime? Pin
Sean Michael Murphy29-Oct-05 16:23
Sean Michael Murphy29-Oct-05 16:23 
GeneralRe: How can I get info about which MenuItem that is clicked at runtime? Pin
Robert Rohde29-Oct-05 22:37
Robert Rohde29-Oct-05 22:37 
GeneralRe: How can I get info about which MenuItem that is clicked at runtime? Pin
M Shafaat30-Oct-05 8:35
M Shafaat30-Oct-05 8:35 
QuestionmciSendString and fullscreen Pin
Sasuko29-Oct-05 13:47
Sasuko29-Oct-05 13:47 
QuestionStrange Behaviour of an Object Pin
1nsp1r3d29-Oct-05 13:24
1nsp1r3d29-Oct-05 13:24 
Hi all,

I've encountered a strange behaviour of one of my objects. After it updates itself in a method(updates some private fields) the changes happen when the method is being executed but when execution returns to the line where the method was called, the object is the same as before. Let me show you the code which does this.

<pre>
public enum DConfMode
{
Normal,
NoInit
}

public class DConf
{
private String hostname;
private String database;
private String username;
private String password;

public DConf(DConfMode Mode)
{
switch (Mode)
{
case DConfMode.Normal:
this.Init();
break;
case DConfMode.NoInit:
break;
}
}

public void Init()
{
XmlTextReader reader = new XmlTextReader(DGlobals.ConfFile);

while (reader.Read())
{
switch (reader.Name)
{
case "hostname":
this.hostname = reader.Value;
break;
case "database":
this.database = reader.Value;
break;
case "user":
this.username = reader.Value;
break;
case "password":
this.password = reader.Value;
break;
}
}
reader.Close();
}

public String DbHostname
{
get
{
return this.hostname;
}
}

public String DbDatabase
{
get
{
return this.database;
}
}

public String DbUsername
{
get
{
return this.username;
}
}

public String DbPassword
{
get
{
return this.password;
}
}
}
</pre>
<pre>
DConf conf = new DConf(DConfMode.NoInit);
conf.Init();
Console.WriteLine(conf.DbHostname);
</pre>
So DConf does the problem. In the second code excerpt, echoing conf.DbHostname doesn't do anything, but when I've debugged it, in conf.Init(); the values are clearly populated. So I'm quite confused why this happens. Here's some sample xml which you could use:
<code>
<configuration>
<user>username</user>
<password>samplepass</password>
<hostname>localhost</hostname>
<database>dbname</database>
</configuration>
</code>
As a sidenote, is it safe calling Init(); in DConf's constructor? I suppose no, since it changes fields and the object hasn't been guaranteed to have been fully set up, am I correct? Any help is greatly appreciated.

Regards,
gamehack

-- modified at 19:29 Saturday 29th October, 2005
AnswerRe: Strange Behaviour of an Object Pin
1nsp1r3d29-Oct-05 13:58
1nsp1r3d29-Oct-05 13:58 
QuestionOverwrite one section of binary file Pin
tommazzo29-Oct-05 12:11
tommazzo29-Oct-05 12:11 
AnswerRe: Overwrite one section of binary file Pin
Guffa29-Oct-05 12:27
Guffa29-Oct-05 12:27 
AnswerRe: Overwrite one section of binary file Pin
Dave Kreskowiak30-Oct-05 9:45
mveDave Kreskowiak30-Oct-05 9:45 
GeneralRe: Overwrite one section of binary file Pin
tommazzo30-Oct-05 12:36
tommazzo30-Oct-05 12:36 
QuestionHow to embed newline in a string resource? Pin
Rob Philpott29-Oct-05 8:43
Rob Philpott29-Oct-05 8:43 
AnswerRe: How to embed newline in a string resource? Pin
Judah Gabriel Himango29-Oct-05 15:08
sponsorJudah Gabriel Himango29-Oct-05 15:08 
GeneralRe: How to embed newline in a string resource? Pin
Rob Philpott30-Oct-05 4:59
Rob Philpott30-Oct-05 4:59 
QuestionHow to set limit to the bandwidth usage? Pin
dunbshy29-Oct-05 6:38
dunbshy29-Oct-05 6:38 
AnswerRe: How to set limit to the bandwidth usage? Pin
Dave Kreskowiak29-Oct-05 7:21
mveDave Kreskowiak29-Oct-05 7:21 
QuestionDelphi Dlls in C# Pin
Dave Shaw29-Oct-05 6:38
Dave Shaw29-Oct-05 6:38 
AnswerRe: Delphi Dlls in C# Pin
S. Senthil Kumar29-Oct-05 7:39
S. Senthil Kumar29-Oct-05 7:39 
GeneralRe: Delphi Dlls in C# Pin
Dave Shaw29-Oct-05 13:50
Dave Shaw29-Oct-05 13:50 
Questionpublic static const member? Pin
budidharma29-Oct-05 6:26
budidharma29-Oct-05 6:26 
AnswerRe: public static const member? Pin
S. Senthil Kumar29-Oct-05 7:46
S. Senthil Kumar29-Oct-05 7:46 
AnswerRe: public static const member? Pin
Robert Rohde29-Oct-05 20:49
Robert Rohde29-Oct-05 20:49 
QuestionHow to visualize a machine scheduling plan? Pin
bjung29-Oct-05 6:09
bjung29-Oct-05 6:09 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.