|
OK, my apologies,
you can create a getter/setter method (more Java based) or a property (C# based)
This is exactly the concept of incapsulation.
so to get to a private member of your class you can do this:
C# based:
public string AStringName{<br />
get{<br />
return theprivatemember;<br />
}<br />
set{<br />
theprivatemember = value;<br />
}<br />
}
This allows you to check if value has correct value (according to your needs) before actually setting them.
eg.:
classinstance.AStringName = "Hello CodeProject!";
will result in the theprivatemember = "Hello CodeProject!"
You can do the same for int, arrays and even objects.
good luck!
No hurries, no worries.
|
|
|
|
|
No apologie needed (no offense taken )
this solves the private/protected issue of my problem but i still need to pass and
store a reference to the Parent object.
See my reply[^] on the solution J4amieC of to understand what i mean.
I have used this simple example to state what I need, I know that the suggested solution works perfect in this case, but the real object model is more complex then this.
codito ergo sum
|
|
|
|
|
If you used to solve it in seconds using references using C++, why cant you solve it in seconds using references in C# AM I missing something?
public class Data
{
public string strText;
Formatter formatProtocol;
public Data()
{
formatProtocol = new Formatter(this);
}
}
public class Formatter
{
private Data toFormat
public Formatter(Data theData)
{
this.toFormat = theData
}
void FormatNow()
{
this.toFormat.strData = "Hello reference";
}
}
|
|
|
|
|
Thanks for the response.
I see few problems with this approach.
1. The Formatter has to know the structure of the Data object this will lead to difficulties when I need to support multiple non-inherented classes Data1, Data2;
2. This alsoo breaks security when the modifier of the member is protected or private, here it needs to be public. Or can I make the two class friend of each other.
3. I'm not sure about this one, but isn't there a Garbage collection issue. I mean both objects point to each other. But I can only 'delete' one (Set the Data object = null)
In c++ i'm used to pass only the data that the other class needs to know/change.
If it only was a function I could pass the string with the ref or out token.
But i need to store it for later processing.
I'm really stuck here
codito ergo sum
|
|
|
|
|
BadKarma wrote: The Formatter has to know the structure of the Data object
Isnt this true of anything termed a "formatter"? If I am to format a word document, I have to have the word document right? I cant format it it i cant see it!
BadKarma wrote: This alsoo breaks security when the modifier of the member is protected or private, here it needs to be public. Or can I make the two class friend of each other.
Make them internal if you like, or a better solution is for all data structures to implement an interface and take that interface in the ctor of the formatter.
BadKarma wrote: I'm not sure about this one, but isn't there a Garbage collection issue. I mean both objects point to each other. But I can only 'delete' one (Set the Data object = null)
No issue, it will all be taken care of for you by the runtime.
|
|
|
|
|
I know your pain, I was experience C/C++ withdrwals too. Here's my take: you don't need any pointers in managed safe code. In system code (i.e. unmanaged you can still use them). Now with that said most applications are more easily maintained and written if they leverage the C# managed classes.
You still have Ref and plus a new Qualifier call Out. But instead of operating on addresses, all C# logic is based on arrays and indices. So I could have an 100 item array of int called myList. If I call a funtion called AddTheValues it might look like this:
<br />
public long AddTheValues( int[] numbers )<br />
{<br />
long total = 0;<br />
<br />
for ( int i=0; i < numbers.Length; ++i )<br />
total += numbers[i];<br />
<br />
return total;<br />
}<br />
Out is sort of like a built in malloc or new that a function returns thru the parameter list instead of as a return value. Good fpr special allocator type code.
<br />
public void NextValueList( out int[] num, int size )<br />
{<br />
num = new int[size];<br />
}<br />
Ref is used when like in C++ we are concerned about operating the SAME structure. In C# you normally don'd have to clean up (i.e. free) new'd elements. This is true for the general case. BUT if you have hairy I/O classes then there is a destructor equiavlent called IDisposable. Basically you derive your C# class from this Interface and it provides the Dispose() method you can customize to clean up.
Good Luck
Mike Luster
CTI/IVR/Telephony SME
|
|
|
|
|
Hello!
I have a very specific question and that is about how to inherit a visual
control for example the control System.Windows.Forms.TextBox without causing
the environment to delete the control when there are some compile errors.
It's the same problem with any visual control that you inherit. The control
is deleted as soon as you use the View Designer when there is compile error.
It's very easy to reproduce my problem. You can do it in this way.
1. Create a class called ExtTextBox like this. In my example here I have
removed the namespace. But if you include namespace make sure you have
access to it.
public class ExtTextBox : System.Windows.Forms.TextBox
{
public ExtTextBox() {}
}
As you can see this class ExtTextBox inherit from the ordinary components
System.Windows.Forms.TextBox in the .NET framework
2. Create a windows form with any name. The default is Form1
3. Use the View Designer and drag the control TextBox into the window form.
My control was called textBox1
4. Because I want the control textBox1 to be an instance of ExtTextBox I
have to edit the InitializeComponent() I don't have any other idea.
Here is an extract from my windows form called Form1.
Only the interesting rows is written. Two rows is important here.
First saying that control textBox1 is of type ExtTextBox.
Second edit the InitializeComponent and say that textBox1 is an instance of
ExtTextBox.
public class Form1 : Form
{
private ExtTextBox textBox1;
...
...
...
Private void InitializeComponent()
{
this.textBox1= new ExtTextBox();
...
...
...
}
}
5 Compile. Hopefully you don't get any compile errors. When you run the
application only the textBox is being displayed. The problem might start
even here. If you get any compile error and you use the View Designer the
control named textBox1 is being deleted.
6 If you don't get any compile error make a change so you get a compile
error and then use the View Designer the control named textBox1 is being
deleted.
7 Now to my question. I can't use controls that being deleted automatically
when I get compile error as soon as I use the View Designer.
8. If I want to use inheritance on visual control how do I do. I just can't
have it as it is now.
9 I just can't use inheritance in the way I do now.
10. I hope that you have a good suggestion how I should use inheritance on
visual control to avoid this kind of problems.
Additional information: I have a project containing
several forms and some code class files. One file in the project is a code
class file which contains this ExtTextBox in this way.
public class ExtTextBox : System.Windows.Forms.TextBox
{
public ExtTextBox() {}
}
When you build the project(assemby) and you get some compile error and you
then use the View Designer on a form containing this inherited control the
control will be deleted.
I have also noted that you can avoid that the control is being deleted but
it's a very annoying way to do it on.
Before you build the project(assembly) you click on Windows->Close All
documents.
Then you build and you get some compile error and you can still use the View
Designer and see the control.
I just can't use that solution having to close all the documents every time
before I build the project.
When I use inheritance I want to extend for example the TextBox class by
additional functionality.
If I create a userControl(see below) for example like this. I can't extent
the class TextBox with additional functionality because the control is a
member in the UserControl class. I can extend the functionality of class
UserControl1 but that is not what I want.
public class UserControl1 : System.Windows.Forms.UserControl
{
private System.Windows.Forms.TextBox textBox1;
...
...
...
private void InitializeComponent()
{
this.textBox1 = new System.Windows.Forms.TextBox():
...
...
...
}
}
So the main question is how do I do if I want to inherit(extend) a visual control class for example TextBox without having the TextBox control to be deleted as soon as I use View Designer.
Is it possible that my problem is a kind of bug in the .NET framework.
I use VS 2003.
//Tony
|
|
|
|
|
How can i remove a datarow from a dataset after validating some new added records without traversing the whole datarow collection. If i get the dataset by using GetChanges(DataRowState.Added) method it returns a new dataset hence if we enumerate on it. It doed not allow to delete in actual dataset.
<pre>
DataSet dstAdded=dst.GetChanges(DataRowState.Added)
foreach(DataRow dr in dstAdded.Tables[0].Rows)
// Some validation ...
dstAdded.Remove(dr) // Removes from Added Dataset
dst.Remove(dr) // Gives an error DataRow does not belong to dataset
</pre>
|
|
|
|
|
I am developing a client server application. For to do that I opend the port 1234 in two machines and send some data to destination.
UdpClient udpClient = new UdpClient();
udpClient.Connect(123.123.123.123,1234);
Byte[] sendBytes = Encoding.ASCII.GetBytes("TEST");
udpClient.Send(sendBytes,sendBytes.Length);
But I am working in a LAN. Means my IP address is local to this LAN. I want to communicate to the machine in a different network. How can I get the actual IP address ?. Eg : my ip address is 192.168.1.16 ( if give the command ipconfig in command window). Its local to my network. But my IP in the global status is our router IP. The how can I identify each computer from another network ?. How yahoo messanger in identifying each computer in the lan ?
any help Please ...
Thanks in advance
Cheers
Jijo
|
|
|
|
|
To get your externnal IP adress you can go to one of the many sites that provide this information.
If you want to know how the router keeps track of the traffic, read up on NAT[^].
---
b { font-weight: normal; }
|
|
|
|
|
|
I am working at a project about using IE printing components. So the IHTMLDocument2 interface was adopted by me. But i need to user IPersistStreamInit interface of IHTMLDocument2. Because the IPersistStreamInit is in System.Windows.Forms.UnsafeNativeMethods, which is declared as internal, I can't declare any variables with data type of IPersistStreamInit. Recently I have learned about the reflector, but this seems not feasible. Who can tell me how to do this? Thanks very much.
|
|
|
|
|
Hai Folks.......
I am using Nullable.Wrap() function with beta version .Now i am upgrade to new release .I dont why they removed this function from Nullable class .OK anybody know how can i change my current code to work properly ..
With Regards & Thanks,
Kiran Kumar Singani
|
|
|
|
|
When i use Keypress to catch Keys in TextBox. When it run, i want to copy A text from word, notepad....But i can not use Right click/paste on it. I have Catch "Ctrl+V" it is ok.
Now i want to Fix it.
Please help me!
superdragon
|
|
|
|
|
i'm sorry, i have some misktakes with textbox Event changevalue. That is reason i did not do what i want.
superdragon
|
|
|
|
|
why my search function in cystal report cannot work when i type a string, the result always display "end of search"
angela
|
|
|
|
|
Who can help me this problem with C# program?
dny
|
|
|
|
|
I've worked with a couple barcode readers from Symbol a few years back. Once the data was scanned the "wand" or reader in our terms was put into the well (i.e. the RS-232 conversion port). So in my case as soon as the wand touched the port it started blasting ASCII data. The data was delimited by START and END bytes and it was a halfway tricky exercise to make it bulletproof. Reading RS-232 was similar to writing an Interrupt Service Routine except you have to deal with behavior of the UART (Universal Async Recv Transmit). I suspect you are still up against that to some extent but these days I have heard the vendors have SDKs. Also, you can probably find a solution you can adapt by googling the net.
Good Luck
Mike Luster
CTI/IVR/Telephony SME
|
|
|
|
|
So C# has a HashTable in the form of Dictionary<K,T> – That’s great std did not have this, and it was lacking for its absence.
C++ C#
List<T> LinkedLink<T>
Slist<T> Queue<T> (if that’s all you used slist<T> for then okay) // I can’t remember the c++ single linked list name.
Slist<T> Stack<T> (Ok, so maybe there’s more code generated in c++ than needed)
Vector<T> List<T> (misleading name for me, and I can not see doco on the behaviour of deleting/inserting in the middle, realloc? Memmove?)
Now the gaps:
?? Dictionary<K,T> (Great! We have a HashTable this is cool)
?? SortedDictionary<K,T> (Curious – more comments below)
Map<K,T> ?? (Umm? Does this gap imply that we shouldn’t need a tree container?) (map<K,T> and set<T> are red-black trees)
Set<T> ?? (Again, what does this absence mean? A Dictionary<K,T> will do in this case, but there is extra unnecessary code there).
In practice we may find that we can use the SortedDictionary<K,T> where we used to use map<K,T>, but what is the cost/benefit of each?
I don’t know, I don’t know how to find out apart from testing it!
So, I’m asking you! Please what is going on in these containers?
Especially List<T> and the realloc/memmove issue.
Jules.
(Excuse my poor formatting, its been a while between posts)
|
|
|
|
|
I am a C++ guy also! I cannot answer your question. You probably already know that these generic containers are managed on the GC heap. Thus, any realloc/memmove issues are probably managed memory issues. The generic containers are faster and more efficient than the object-based ones but you pay for the managed memory features.
|
|
|
|
|
definetly sounds plausable - However, as you suggest it implies that the 'array' inside List<t> is not actually a continuous block of memory.
If this is the case then I assume (of course) that there is at least one extra level of redirection to get to the data from the array indexing. I doubt is does what vector does, which it only grow and only shrink when the appropriate method is called (I forget what its called resize() or something).
|
|
|
|
|
hi
new to using c# and datagrids and having a few issues. i have a couple of issues that would help me along.
i create a connection to my data, a dataadapter and then a dataset. i fill the dataset and then link my datagrid to it - this all works fine.
1. if the user double clicks on a cell/row, i want to open another form, passing info about what has been clicked. i can see how to pass the location of the click, but not the actual data itself. do i get this from the datagrid, or somehow from the dataset?
2. single/double-clicking on the grid should highlight the entire row, and not just the cell - is there a way of doing this?
many thanks!
barry
-- modified at 17:57 Wednesday 15th March, 2006
ps. also need an absolute reference to using datagrids - if it exists!
|
|
|
|
|
1. Have a look at the HitTest function. It takes a pixel coodinate and tells you which cell is positioned there. With this info you can use the indexer of the grid:
private void dataGrid1_Click(object sender, System.EventArgs e)
{
Point screenPos = Cursor.Position;
Point gridPos = dataGrid1.PointToClient(screenPos);
DataGrid.HitTestInfo hti = dataGrid1.HitTest(gridPos);
if (hti.Type == DataGrid.HitTestType.Cell)
Console.WriteLine("Contents: " + dataGrid1[hti.Row, hti.Column]);
}
You could also use the MouseDown event. In this case you would get the relative grid pixel coordinates right in the event arguments.
2. Have a look at the Select and Unselect functions from the datagrid.
|
|
|
|
|
Is there a way to capture mouse input on a form made transparent via the TransparencyKey?
The same problem, a different type of solution:
I have a custom user control designed that has a transparent background using the following technique:
protected override void OnPaintBackground(PaintEventArgs e)
{ //base.OnPaintBackground(e);
}
//add transparent property
protected override CreateParams CreateParams
{
get
{
CreateParams cp = base.CreateParams;
cp.ExStyle |= 0x20;
return cp;
}
}
This effectively stops the program from drawing the background of the control, so the painted object is drawn on a transparent background. However, when repaint the object in a different position on the control, the old image remains (because the background was not redrawn to erase the old image). The image changes with every mouse move, so I need an effecient way to erase the old image while preserving transparency.
A lot of methods to erase the old image, ie, erase the control and start with a clean slate, destroy the transparent effect.
Any thoughts anywhere?
|
|
|
|
|
Just a bump to make sure this post isn't lost forever.
|
|
|
|