|
Hi Chris
try 'protected abstract void', you don't implement the function body and the whole class must be abstract.
-------------------------------
Carrier Bags - 21st Century Tumbleweed.
|
|
|
|
|
Hi all,
Please help me in providing example of using get(),set().
What exactly and why necessary get set methods.
Pls illustrate me with example.
Thanks and reagards
Have a Nice Day Dudes
|
|
|
|
|
You can use Proprty setting to handle the data member in a class.
Like
Class Example
{
private string name;
public string Name
{
get { return name; }
set { name = value; }
}
}
Example exple = new Example();
You can set the value like
exple.Name = "Kushi Bobby";
You will get that property name thru the object
You can get the value like
string name = exple.Name;
My small attempt...
|
|
|
|
|
So, it's considered a bad practice in OOP to have member variables defined as public in your classes. So you define them as private and you read and write theirs values through "getters" and "setters" which are public.
Properties are just a fancy way to ease the use of get and set methods, as they give you the illusion of accessing the memeber variable directly.
|
|
|
|
|
blackjack2150 wrote: Properties are just a fancy way to ease the use of get and set methods, as they give you the illusion of accessing the memeber variable directly.
It depends on the language. In MSIL Properties compile into two methods with the name of the property, but with one prefixed get_ and the other set_. In Managed C++ the get and set methods are explicit called. e.g. get_Name() or set_Name()
|
|
|
|
|
Visual J# is an OOP and instead of properties for .NET objects their are get and set methods for each .NET property when compared to other .NET languages like C# and VB.
blackjack2150 wrote:
Properties are just a fancy way to ease the use of get and set methods, as they give you the illusion of accessing the memeber variable directly.
Basically
Regards,
Thomas Stockwell
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
Visit my homepage Oracle Studios[ ^]
|
|
|
|
|
and of course the advantage of properties are:
- you can make something public readable, but not public writeable
- you can add code to the get/set part of the property, so you can easily
count the operations, log them, modify the internals of your class, whatever,
all without changing the code that uses your class.
|
|
|
|
|
I need some help on the following problem. I need to have a object set itself to null. Is this in any way possible?
|
|
|
|
|
try
obj = null
Mubashir
Software Architect
Storan Technologies Inc, USA
Every job is a self portrait of the person who did it.
|
|
|
|
|
I will explain myself a bit.
public class A {
public void SetToNull() {
}
}
I know that I can set it like this below. But that is not what i want.
public class A {
public void SetToNull()
{
}
}
public class B {
public A a = new A();
public void SetToNull()
{
a = null;
}
}
It needs to be like this.
public class A {
public void SetToNull()
{
}
}
public class B {
public A a = new A();
public void SetToNull()
{
a.SetToNull();
}
}
|
|
|
|
|
The answer is no because the the object does not have any knowledge of who holds a reference to it.
There may, however, be a way around it using weak references. The problem with that solution is that the point at which the references become null is non-deterministic.
You could also implement IDisposable and Dispose of the internals of the object when you don't need it. However, anything accessing the object would have to be able to handle the fact that the object may exist, but it has already been disposed of.
The above work arounds do not take into account the overall big picture. It would be better to know what it is you are trying to achieve. That way we could probably suggest a better solution.
|
|
|
|
|
Hi,
an object can not set itself to null.
an object is a piece of code+data, and what you use to access an object
really is a reference (often also called object, but that is not strictly correct).
Now an object cannot access its reference(s) in general, since an object is
not aware of its references.
In special cases you can do something, but that requires you get access to the
reference, typically by using the ref keyword, as in:
Nullable A=new Nullable();
a.NullifyMyRef(ref a);
a.Something();
class Nullable {
public void NullifyMyRef(object ref obj) {
obj=null;
}
}
But what is the use of all this ???
Most scenarios I can come up with are a result of bad OO practices.
The one good use I could come up with is something like the Dispose() method
that may want to nullify its own reference; the fact that it does not proves
to me once more it can not be done.
|
|
|
|
|
Matglas wrote: I need to have a object set itself to null. Is this in any way possible?
If you mean what I think you mean then the answer is no.
Do you mean something like this:
MyObject obj = new MyObject();
...
obj.DoSomeOperationThatSetsObjToNull();
Assert.IsNull(obj);
The answer is no because the the object does not have any knowledge of who holds a reference to it.
There may, however, be a way around it using weak references. The problem with that solution is that the point at which the references become null is non-deterministic.
You could also implement IDisposable and Dispose of the internals of the object when you don't need it. However, anything accessing the object would have to be able to handle the fact that the object may exist, but it has already been disposed of.
The above work arounds do not take into account the overall big picture. It would be better to know what it is you are trying to achieve. That way we could probably suggest a better solution.
|
|
|
|
|
Ok I hope my english is good enough to explain what I want to achieve.
I have a deserialized object from a xml file. This object is shown in a treeview to edit the content. I want to have the option to remove a object by clicking on it and getting it context menu. This context menu is unique for every object. I get it by a GetContextmenu method that is implementated by a Interface. The eventhandlers for each menuitem is set to a method in that object.
I hope the situation is clear. Otherwise i have to make some code to show it.
|
|
|
|
|
I think what you need is a ToParent reference for each object, and to have the parent set the specific child to null.
--
CleaKO The sad part about this instance is that none of the users ever said anything [about the problem].
Pete O`Hanlon Doesn't that just tell you everything you need to know about users?
|
|
|
|
|
I already thought so but did not directly find a way to set the parent on Deserialization. Or I have to Recursivly go through every object.
|
|
|
|
|
This is the object situation. I copyed some code, to show you. The DeletePage() needs to delete the page from the Pages property in the Document .
public class Document : ITreeView
{
public Document() { }
private PageCollection _pages = new PageCollection();
[XmlElement(ElementName = "page")]
public PageCollection Pages
{
get { return _pages; }
set { _pages = value; }
}
#region public methods
public Document Deserialize(string file)
{
}
public void Serialize(string file, Document doc)
{
}
#endregion
#region ITreeView Members
public ContextMenu GetContextMenu()
{
ContextMenu docContext = new ContextMenu();
return docContext;
}
public ObjectTreeNode GetTreeNode()
{
return new ObjectTreeNode(this, "document", 0, 0);
}
#endregion
}
public class Page : ITreeView
{
public Page() { }
#region properties
#endregion
#region ITreeView Members
public ObjectTreeNode GetTreeNode()
{
return new ObjectTreeNode(this, "page " + _pagenumber, 0, 0);
}
public System.Windows.Forms.ContextMenu GetContextMenu()
{
ContextMenu pageContext = new ContextMenu();
MenuItem delItem = new MenuItem("Delete", new EventHandler(DeletePage));
pageContext.MenuItems.Add(delItem);
return pageContext;
}
public void DeletePage(object sender, EventArgs e)
{
}
#endregion
}
|
|
|
|
|
hi,
I am having a richtextbox and in the menu item got Undo option.
the code is
UndoMenuitem()
{
if(Richtextbox1.canundo)
{
Richtextbox1.undo();
}
}
this code is undoing the all actions at a single click.
Instead of chracter by chracter.
Pls help me
With regards
prasad
|
|
|
|
|
You can't override the Undo operation on the RTB to do this. What you would have to do is roll your own Undo/Redo mechanism and use that.
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
Hello,
I am new to C# threading and I am having problems accomplishing a task. To give a quick overview as to what I am trying to do: I have many user controls on a single form that each present different data. This is a small utility that displays the status of different applications and systems. Each user control, as of now, has two threads. 1 thread will update the data source and the other thread will update the user interface.
My problem is that I do not wish to lock the Form while one user control tries to update itself. I have tried two approaches.
1.) I called lock(myDataTable) and performed all updates to the datatable before the thread is called to update the user interface. This did not work until I changed my code to lock(this). I was getting threading errors where the datatable was only about 1/2 populated. When I switched over to lock(this), my gui started locking again on an update.
2.) Thread the threads (god help me). I have two methods: updateData and updateGui. I made a wrapper method called refreshAll that would create a new thread job on updateData, sleep until it was finished, and then make another threaded call to updateGui. When my timer tick event fired I would make a threaded call to refreshAll. Big surprise on this giving me weird gui hang-ups.
Sorry if this is confusing. I will re-iterate on areas if I was not clear. Any help / approaches would be much appreciated. Thanks!
|
|
|
|
|
Hello,
Have you invoked the method which refreshes the GUI?
All the best,
Martin
|
|
|
|
|
Yes:
private delegate void displayCallback();
private void display()
{
if (InvokeRequired)
{
BeginInvoke(new displayCallback(display));
return;
}
....
}
|
|
|
|
|
ATCsharp wrote: I have many user controls on a single form that each present different data. This is a small utility that displays the status of different applications and systems. Each user control, as of now, has two threads. 1 thread will update the data source and the other thread will update the user interface.
What causes an update? You have a data source that's being updated as well as a user interface, so where does the update come from?
If the updates take awhile, can you represent the progress of the update to the user (probably using a progress bar) so that the app doesn't appear stuck?
More info is needed.
|
|
|
|
|
Hi all,
i am writing an application to communicate between local and remote machine using STAF tool.
I can have a one way communcation but i want to have a both way communication. Like local machine abc.exe runs def.exe over remote machine and then remote machine goes back to local machine to ask what task to perform and then local exe says calc.exe to run and remote machine performs that.
So below is the psueudo code to achieve this but could any one help me out in converting this to C#.NET. i tried this out but i am getting exception at the moment. So here is the psuedo code
abc.exe (started by machineA)
-- STAFHandle::create("ABCApp", handle);
-- handle->submit("machineB", "PROCESS", "START COMMAND def.exe");
-- handle->submit("local", "QUEUE", "GET WAIT");
---- when the "ReadyForInput" message is received from DEFApp,
----- handle->submit("machineB", "QUEUE", "QUEUE NAME DEFApp MESSAGE Start:Calc");
---- when the "Finished" message is received from DEFApp, continue to next executable to run and queue another message to DEFApp, etc...
def.exe (started, by abc.exe, on machineB)
-- STAFHandle::create("DEFApp", handle);
-- handle->submit("machineA", "QUEUE", "QUEUE NAME ABCApp MESSAGE ReadyForInput");
-- handle->submit("lcoal", "QUEUE", "GET WAIT");
--- when the "Start" message is received from ABCApp, parse the program to run (Calc)
---- handle->submit("local", "PROCESS", "START COMMAND Calc.exe");
---- when Calc.exe completes,
----- handle->submit("machineA", "QUEUE", "QUEUE NAME ABCApp MESSAGE Finished:Calc");
//submit function is already created with parameters which submits the command to local or remote machine.
Thanks a lot.
SS
-- modified at 8:05 Monday 16th April, 2007
|
|
|
|
|
Software_Specialist wrote: i tried this out but i am getting exception at the moment.
Show us the code you got so far and tell us what exception you're getting.
It's quite hopeless to wait for someone turning your pseudo-code into running C# code. This is a forum for helping others with their problems and not doing their whole work.
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|