|
i have the idea about inheritance, but the problem is about the performance when a child class is assigned to a parent class.
please let me explain.
class A is the parent of class B ,an d is the parent of C like wise
A->B->C->D->E->F->G
then i know that when i create an object from class G all the constructors from A to G is called.
Now when i'm assigning an object of G to object of A
A aa = new A();
G gg = new G();
aa = gg;
object "gg" is casted to A type , then is this happens like it happened in creating "gg" all through the hierarchy, or is it just one step from G to A... or is something else happens.. and what about the performance?
|
|
|
|
|
prasadbuddhika wrote: it happened in creating "gg" all through the hierarchy,
No. AFAIK, it is just one step.
Type casting performance - you might want to take a look here.
My signature "sucks" today
modified on Monday, May 24, 2010 11:18 AM
|
|
|
|
|
prasadbuddhika wrote: A->B->C->D->E->F->G
A aa = new A();
G gg = new G();
aa = gg;
nothing gets cast. All the last statement does is forget the existing instance of class G is a highly specialized instance of class A.
If class G represents gray cats, and A represents animals, gg may be the little gray kitten you found yesterday on your doorstep and decided to call Fluffy; still your last statement just says: I'll forget it is gray, I'll forget it is a cat, I just remember it is an animal. But then, it won't meow anymore, as the Meow() method is not in class A, it only exists in F and G.
There is no activity involved.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
|
|
|
|
|
thanx for tour explanation
|
|
|
|
|
this is called upcasting.
Reference is to 'A', but type still remains 'G'.
This type of upcast later is very useful in dynamic method dispatch.
|
|
|
|
|
thanx new word for me upcasting
|
|
|
|
|
Hello all!
I'm new to asp.net and i'm trying to bind some XML data to a gridview.
abviously I'm not understanding how to do it properly because that my code doesn't seem to
work...Can anyone could help me please?
this is my xml:
#########################################
<?xml version "1.0" encoding "utf-8"?>
<dictionary>
<item>
<key>
<string> hello world </string>
</key>
<value> <anytype xmlns:q1="http://www.w3.org/2001/XMLSchame" d4p1:type="q1:int"
xmlns:d4p1="http-instance">45</anytype>
</value>
</item>
</dictionary>
and this is my code:
########################################
string path = "D:\\myXmlFile.xml";
DataSet oDs = new DataSet();
oDs.ReadXml(path);
GridView1.DataSource = oDs;
GridView1.DataBind();
thanks
Tom
modified on Saturday, May 22, 2010 8:57 AM
|
|
|
|
|
You would actually find more people answering this question if you would post it in the ASP.Net forum.
My signature "sucks" today
|
|
|
|
|
|
Don't cross post. You have started here and answers have been given here, remove the one you have just posted in the ASP.NET forum before anyone answers there as well.
Read the forum guidelines.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Hello, I have an Image I recieve from a stream and I need to save it in the File Format .PBM (Portable Bitmap) because the library I am trying to use only accepts .PBM format. Any ideas How i would do this?
|
|
|
|
|
Spilled wrote: Any ideas How i would do this?
No, however I would start here[^].
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
|
|
|
|
|
Hi Experts,
What i am trying to achieve here is a bit tricky. Let me brief on a little background first before going ahead.
I am aware that we can use a enum as a type to a parameter of a method. For example I can do something like this (a very basic example)
namespace Test
{
class DefineEnums
{
public enum MyEnum
{
value1 = 0,
value2 = 1
}
}
class UseEnums
{
public void UseDefinedEnums(DefineEnums.MyEnum _enum)
{
}
public void Test()
{
UseDefinedEnums(DefineEnums.MyEnum.value1);
}
}
}
What i need to do is create a dynamic Enum and use that as type in place of DefineEnums.MyEnum mentioned above.
I tried the following.
1. Used a method which i got from the net to create a dynamic enum from a list of strings. And created a static class which i can use.
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Reflection.Emit;
namespace Test
{
public static class DynamicEnum
{
public static Enum finished;
static List<string> _lst = new List<string>();
static DynamicEnum()
{
_lst.Add("value1");
_lst.Add("value2");
finished = CreateDynamicEnum(_lst);
}
public static Enum CreateDynamicEnum(List<string> _list)
{
AppDomain currentDomain = AppDomain.CurrentDomain;
AssemblyName aName = new AssemblyName("TempAssembly");
AssemblyBuilder ab = currentDomain.DefineDynamicAssembly(
aName, AssemblyBuilderAccess.RunAndSave);
ModuleBuilder mb = ab.DefineDynamicModule(aName.Name, aName.Name + ".dll");
EnumBuilder eb = mb.DefineEnum("Elevation", TypeAttributes.Public, typeof(int));
int i = 0;
foreach (string item in _list)
{
eb.DefineLiteral(item, i);
i++;
}
return (Enum)Activator.CreateInstance(eb.CreateType());
}
}
}
2. Tried using the class but i am unable to find the "finished" enum defined above. i.e. I am not able to do the following
public static void TestDynEnum(Test.DynamicEnum.finished _finished)
{
}
I guess the post has become too long but i hope i have made it quite clear.
Please help!
Thanks in advance!
Regards,
Samar
modified on Friday, May 21, 2010 4:43 AM
|
|
|
|
|
Hi Experts,
Any suggestions on this?
Regards,
Samar
|
|
|
|
|
Don't be so damn impatient. We are here voluntarily, this is not a paid support forum.
You can't access the finished enum because it doesn't exit. You cut & pasted the MSDN example which names the enum Elevation.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Hi Mark,
I am not impatient. I just wanted everyone to know that this thread is active and not dead. Will take care the next time.
I know the enum "finished" does not exists. That is why i tried and separated the declaration and the caller in separate assemblies and gave reference of the declaration assembly in the caller project. This did not work either.
Also I have clearly mentioned in the post that the method is not built by me and that i have "Used a method which i got from the net".
Last words, it would be appreciated if you use a better language than using words like "damn". This is a forum and not your home.
Regards,
Samar
|
|
|
|
|
dashingsidds wrote: I just wanted everyone to know that this thread is active and not dead
Threads don't die. If someone has an answer, or chooses to respond, they will. You adding a response just shows you are impatient and demanding. Again, these forums are not paid support but are voluntary.
dashingsidds wrote: use a better language than using words like "damn"
I'll damn well use damn wherever I please damnit.
Since you are rude and impatient and can't follow the guidelines and etiquette of this site, you're on your own now.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
The original poster just posted a reminder and did not specifically demand an answer from "Mark Nischalke" and the language was far more superior than your reply. You could have altogether ignored the post.
|
|
|
|
|
Shameel wrote: posted a reminder
Obvuously you are as ignorant of proper ettique here as the OP was.
Shameel wrote: You could have altogether ignored the post.
As could you have ignored this post as well. So what's your point?
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
He also cross-posted -- another no-no.
|
|
|
|
|
I am developing an application using the serial port pin controls when a switch is open or closed, what I do is connect a switch between the pins RTS and CTS (output RTS pin7 to the input CTS Pin8). As a true RTS I have it all the time, pressing the switch changes the state of CTS and through the event PinChanged pick up the change of state and write it down.
The code used is similar to that attached
PrivateSub SerialPort1_PinChanged(ByVal sender As System.Object, ByVal e As System.IO.Ports.SerialPinChangedEventArgs) Handles SerialPort1.PinChanged
If e.EventType = IO.Ports.SerialPinChange.CtsChanged Then
class Escribelog(“TZ”)
EndIf
EndSub
But do not get me run this event, even though I look for www, I find that it is advisable not to put too much code in that event, since it must resolve what has very quickly to be available again, which can not be changed controls, but I see no reason why one can not do what I want. But even if ordinary VB in me a working PC.
I read something that perhaps signals the sense that I use have changed, so that as this email on a PDA, when I set the RTS to true, I'm really not one but putting 0, so that pressing connect switch but both RTS to CTS 0, and therefore I do not detect anything, but do not know if this is true or I've misunderstood.
You know how I can find out why it does not work this lucky code.
Thank you very much
|
|
|
|
|
You may have any of the following issues, or combination thereof:
1.
AFAIK you need to open the serial port, and obviously you need to wire an event handler to it, for the handler to become active at all.
2.
connecting RTS to CTS may or may not work, one is an input pin, one is an output pin; if the unconnected input pin has the same logic level as the output pin, then connecting them together won't change a thing. So your scheme will only work for one specific value of the RTS pin. I never can remember the levels, so you would have to look up the details.
3.
almost all asynchronous handlers, and the SerialPort ones for sure, run on ThreadPool threads. Which means they cannot reliably access any GUI Controls. You can (for debugging purposes) include a MessageBox.Show(), that should work; but you can't simply do myLabel.Text="CTS has changed";
This article[^] provides more information about that.
Some remarks:
- a mechanical switch will "bounce", so for throwing the switch once, you are likely to get several "pin changed" events.
- all serial port events get queued; if your event handler takes longer, additional events will get queued and will call your handler with some delay, so you loose the real-time behavior. (That would also be true with you clicking a Button that has a slow handler).
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
|
|
|
|
|
Hello Luc, thanks for this information, but after that, I think I should explain my situation, and sorry for my english:
•On the project I open de serialport, and I haven’t problem with that, and also I connect the two pins whit a wire and a switch.
•I read others projects that use the same concept for running ok, but I don’t see its code, also I read that the two pins are the same logic: I probe to connect positive and negative signal RTS and in both cases the event PinChanged no jump
•I know the situation of the serialport event cannot access any GUI Controls, so I don’t use it. In my event I only stop a timer, write in a log and finally I restart the timer. I use this timer to write to a log periodically, and I think my problem is in this timer, but I delete it and the even still not working
After that I don’t know where to go
About of remarks, when I get running my project ok, I study the problems whith “bounce” or delay, but I think I will not problems with it, because is not a critical solution.
|
|
|
|
|
OK, some more points you should check:
- you are using the correct SerialPort;
- the SerialPort is open;
- it has CanRaiseEvents true;
- you are using the right pins;
- your switch is operational;
- measure the voltages you are getting between the GND pin and any relevant pin;they must be OUTSIDE the range [-3,+3] Volt and throwing the switch must change the input voltage from one side to the other.
- try it with as simple a PinChanged handler as possible (a single MessageBox.Show)
If all else fails, show us code.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
|
|
|
|
|
Hello Luc, on response at your message, I review the pointS you remarks,and:
-I use the correct serial port, COM1, because I open it and if I change the RtsEnable the true at false, the RTS pin 7 change his signal sign
-I review the pin another time, ans I use the correct, pin 7 and 8
-When I change the RtsEnable the true at false, the RTS pin 7 change to 6.7V at -5.7V, in both cases is this signal that I connect to CTS Pin 8
-Finally I probe with as simple a PinChanged handler as possible and I continue whithout response
The only point what I don't know to do is the use of "CanRaiseEvents" How can i do?
Thanks for all
I send my code:
Imports System
Imports System.IO
Imports System.Threading
Public Class Control_entrada
Dim bitRTS As Boolean
Dim bitDTR As Boolean
Dim estadoCTS_OLD As Boolean
Private Sub comm1_PinChanged(ByVal sender As Object, ByVal e As System.IO.Ports.SerialPinChangedEventArgs) Handles comm1.PinChanged
''Timer1.Enabled = False
MessageBox.Show("SI")
''Call ctrl_log.EscribeLog("TZ")
''Timer1.Enabled = True
End Sub
Private Sub Timer1_Tick(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Timer1.Tick
' Utilizamos un Control Timer para mostrar en los text el dia y la _
'hora del sistema. La propiedad intervalo del control timer esta en 1000 milisegundos
Call ctrl_log.EscribeLog("CT")
End Sub
Private Sub cmdRTS_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdRTS.Click
If bitRTS Then
cmdRTS.Text = "Activar control puerta (RTS)"
bitRTS = False
Call ctrl_log.EscribeLog("PP")
Else
cmdRTS.Text = "Activado control puerta (RTS)"
bitRTS = True
Call ctrl_log.EscribeLog("AP")
End If
'AQUI SE ACTIVA LA SEÑAL DE RTS PARA VIGILAR LA APERTURA DE LA PUERTA
'esta señal sera constantemente 1, y en caso de abrir la puerta el interruptor la conecta al pin CTS
'que pasara de ser 0 a ser 1 y es lo que detectaremos para escribir en el log la apertura de puerta
'comm1.RtsEnable = bitRTS
comm1.RtsEnable = True
End Sub
Private Sub cmdparar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdparar.Click
If comm1.IsOpen Then
comm1.Close()
End If
Me.Text = "Puerto - cerrado"
Call ctrl_log.EscribeLog("PG")
cmdAbrir.Enabled = True
cmdRTS.Enabled = False
cmdDTR.Enabled = False
Timer1.Enabled = False
End Sub
Private Sub cmdAbrir_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdAbrir.Click
' por si el puerto ya está abierto por otra aplicación
On Error Resume Next
comm1.Open()
If comm1.IsOpen Then
Me.Text = "Puerto - abierto"
Call ctrl_log.EscribeLog("AG")
cmdAbrir.Enabled = False
cmdRTS.Enabled = True
cmdDTR.Enabled = True
''Timer1.Enabled = True
Else
Me.Text = "no se puede abrir el puerto"
End If
End Sub
End Class
Public Class ctrl_log
Public Shared Sub EscribeLog(ByVal tip_msg As String)
Dim direccionArchivo As String
direccionArchivo = ".\ctrl\Ficherito.txt"
Dim sw As StreamWriter = File.AppendText(direccionArchivo)
Dim txt_log As String
Dim hora As String
Dim fecha As String
Try
hora = Format(TimeOfDay, "HH:mm:ss")
fecha = Format(DateTime.Today, "dd/MM/yyyy")
txt_log = fecha & " " & hora
Select Case tip_msg
Case "PC"
txt_log = txt_log & ": Puerta cerrada" + System.Convert.ToChar(13)
Case "PA"
txt_log = txt_log & ": Puerta abierta" + System.Convert.ToChar(13)
Case "PP"
txt_log = txt_log & ": Parada proc puerta" + System.Convert.ToChar(13)
Case "AP"
txt_log = txt_log & ": Arranque proc puerta" + System.Convert.ToChar(13)
Case "PG"
txt_log = txt_log & ": Parada proc general" + System.Convert.ToChar(13)
Case "AG"
txt_log = txt_log & ": Arranque proc general" + System.Convert.ToChar(13)
Case "CT"
txt_log = txt_log & ": Control" + System.Convert.ToChar(13)
Case "TZ"
txt_log = txt_log & ": Estoy en evento" + System.Convert.ToChar(13)
Case "T1"
txt_log = txt_log & ": Estoy en evento 1" + System.Convert.ToChar(13)
Case "T2"
txt_log = txt_log & ": Estoy en evento 2" + System.Convert.ToChar(13)
Case "T3"
txt_log = txt_log & ": Estoy en evento 3" + System.Convert.ToChar(13)
End Select
sw.Write(txt_log)
sw.Flush()
sw.Close()
Catch exFile As Exception
sw.Close()
MsgBox(("Cannot open " & exFile.ToString()))
Return
End Try
sw.Close()
End Sub
End Class
|
|
|
|
|