473,708 Members | 2,376 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Return-Type in Base & Inherited Class

Hello,

I have a BaseClass and many Classes which all inherit (directly) from the BaseClass.

One of the functions in the BaseClass is to (de)serialize the (inherited) Class to/from disk.

1. The Deserialization goes like:

#Region " Load "

Public Function Load(ByVal path As String) As Object

Return DeserializeXML( className, path)

End Function

Public Function Load(ByVal path As String, ByVal user As String) As Object

Return DeserializeXML( className, path, user)

End Function

#End Region

The "problem" with this approach is that when a class get's instanciated it is returned as an Object instead a the Derived type so I have to Cast it (option strict on):

Dim Setup As New Namespace.Setti ngs.Setup

Setup = DirectCast(Setu p.Load(PathInfo .Settings), Namespace.Setti ngs.Setup)

If I could return it with the right Type the code would be reduced to:

Dim Setup As New Namespace.Setti ngs.Setup

Setup = Setup.Load(Path Info.Settings)

One way to do this is to put the Load-Method in each derived Class (but that wouldn't be very OO), so I'd like to Dynamicaly (genericaly) Change the Return-Type of the Load-Method.

Only: I haven't got a clue how-to!

2. The Deserialization goes like:

#Region " Persist "

Public Sub Persist(ByVal path As String)

Try

SerializeXML(Me , className, path)

Catch ex As Exception

MsgBox(ex.ToStr ing)

End Try

End Sub

Public Sub Persist(ByVal path As String, ByVal user As String)

Try

SerializeXML(Me , className, path, user)

Catch ex As Exception

MsgBox(ex.ToStr ing)

End Try

End Sub

#End Region

The following code is in a Module (in the same project)

Private Sub PerformSerializ ation(ByVal o As Object, ByVal callerClass As String, ByVal path As String, ByVal user As String)

.........

.........

Dim swFile As StreamWriter = New IO.StreamWriter (fileName)

Dim t As Type

Dim pi As PropertyInfo()

Dim p As PropertyInfo

Select Case callerClass.

Case "settings.setup "

t = GetType(Setup)

.........

.........

Case "settings.mails erver"

t = GetType(MailSer ver)

.........

.........

Case "settings.produ cts"

t = GetType(Product s)

End Select

pi = t.GetProperties ()

' Encrypt Strings

For Each p In pi

If p.PropertyType. ToString = "System.Str ing" Then I also think this syntax is "Not Done". What would be the Best Syntax?

p.SetValue(o, Crypto.EncryptS tring(p.GetValu e(o, Nothing)), Nothing)

End If

Next

' Save to Disk

xmlSerializer = New Xml.Serializati on.XmlSerialize r(t)

xmlSerializer.S erialize(swFile , o)

swFile.Close()

End Sub

Not very OO hum!

Instead of passing "an Object" I would like to pass the Type of the Inheriting Class. But how do I "know" that in the BaseClass.

Any clues would be greatly appreciated.

Michael

PS: I use vs.Net 2003

Nov 20 '05 #1
12 3790
Hi Michael,

1. I think we can not pass the ctype function the type of string. But I
think you may take a look at the code below, did that work for you?

Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click
Dim kc As Color = Color.FromKnown Color(KnownColo r.Blue)
Dim cr As Color = Color.FromArgb( kc.ToArgb())
Dim c As KnownColor
For i As Integer = 1 To 137
If Color.FromKnown Color(i).ToArgb () = cr.ToArgb() Then
Debug.WriteLine (CType(i, KnownColor).ToS tring())
End If
Next
Dim o As New derivedclass
o.str = "Test"
o.se()
Dim b As derivedclass
b = o.de()
MsgBox(b.str)
End Sub

Public Class baseclass
Public Sub se()
Dim ser As New Xml.Serializati on.XmlSerialize r(Me.GetType())
Dim writer As TextWriter = New StreamWriter("T est.xml")
ser.Serialize(w riter, Me)
writer.Close()
End Sub

Public Function de() As Object
Dim ser As New Xml.Serializati on.XmlSerialize r(Me.GetType())
Dim fs As New FileStream("Tes t.xml", FileMode.Open)
Return ser.Deserialize (fs)
End Function
End Class
Public Class derivedclass
Inherits baseclass
Public str As String
End Class

2.
PropertyInfo.Pr opertyType Property [Visual Basic]
Gets the type of this property.
PropertyType is readonly property
http://msdn.microsoft.com/library/de...us/cpref/html/
frlrfSystemRefl ectionPropertyI nfoClassPropert yTypeTopic.asp

3.
Even if the method is in the baseclass.
e.g.
Public Function Hello(ByVal o As BaseClass) As String
Return o.GetType().ToS tring()
End Function
but if we pass an derived class instance into the method, we will still get
the derived method's type.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 20 '05 #2
Hi Peter,

Thanks for your reply.

I have though stumbled upon another Issue namely:

I have a LibraryClass "Assembly_Phone "
Assembly_Phone has <Assembly: AssemblyDefault Alias("I don't know.")>
Lets suppose it contains a Method:

Class Hello
Sub WhoIsCallingMe( )
Dim at As Type = GetType(Assembl yDefaultAliasAt tribute)
Dim r() As Object =
Me.GetType.Asse mbly.GetCalling Assembly.GetCus tomAttributes(a t, False)
If IsNothing(r) Or r.Length = 0 Then
MsgBox("No Default defined")
Else
MsgBox(CType(r( 0), AssemblyDefault AliasAttribute) .DefaultAlias)
End If
End Sub
End Class

I have another Assembly (Executable) in antoher Solution "Assembly_E XE"

Assembly_EXE references Assembly_Phone
Assembly_EXE has <Assembly: AssemblyDefault Alias("It's me!")>

Sub Main()
Dim Ring As New Assembly_Phone. Hello
Ring.WhoIsCalli ngMe()
End
End Sub

Running Assembly_EXE should display a Messagbox prompting: "It's me!" BUT
it's prompting "I don't know".

What am I missing here?

Regards,

Michael
Nov 20 '05 #3
Hi Michael,

It is strange that I can not reproduce problem with your code.
But I think you may try to add a debug output in the WhoIsCallingMe method
to see what is the Me.GetType.Asse mbly.GetCalling Assembly actually is.
Based on my test, this will return the exe file which call the dll.
Dim at As Type = GetType(Assembl yDefaultAliasAt tribute)
Debug.WriteLine (Me.GetType.Ass embly.GetCallin gAssembly.FullN ame)
Dim r() As Object =
Me.GetType.Asse mbly.GetCalling Assembly.GetCus tomAttributes(a t, False)

You may have a try and let me know the result.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 20 '05 #4
Hi Peter,

I found out what "went wrong".

I had the 'Me.GetType.Ass embly.GetCallin gAssembly.GetCu stomAttributes( at, False)' in the BaseClass, so it returned it's own Assembly since the Caller was the Derived Class (= same assembly)

'Me.GetType.Ass embly.GetCallin gAssembly.GetCa llingAssembly.G etCustomAttribu tes(at, False)' doesn't seem to do the trick (although it seems logical to me) so I guess I will have to define the Calling Assembly in the (all) Derived Class(es).

Maybe you could come up with a better alternative?

Thanks,

Michael
Nov 20 '05 #5
Hi Michael,

I did not understanding your senario very well.
Do you mean your senario is as below?
you have a BasedClass in assembly liba as below
Imports System.Reflecti on
Public Class BaseClass
Public Sub WhoIsCallingMe( )
Dim at As Type = GetType(Assembl yDefaultAliasAt tribute)
Dim r() As Object =
Me.GetType.Asse mbly.GetCalling Assembly.GetCal lingAssembly.Ge tCustomAttribut e
s(at, False)
If IsNothing(r) Or r.Length = 0 Then
MsgBox("No Default defined")
Else
MsgBox(CType(r( 0), AssemblyDefault AliasAttribute) .DefaultAlias)
End If
End Sub
End Class

and an exe assembly
Module Module1
Public Class DerivedClass
Inherits LibA.BaseClass
End Class
Sub Main()
Dim o As New DerivedClass
o.WhoIsCallingM e()
End Sub
End Module

Based on my test, this will return the "It's me".
If I have any misunderstandin g, please feel free to let me know.

Or can you post a simple sample to demostrator your senario?

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 20 '05 #6
Hi Peter,

I'm sorry. It was my mistake. I just "simplified " my real issue too much.
I give you here a more realistic "Dummy".
There is one additional issue I face : The MarkDirty-Method doesn't work. I guess it's a scoping issue, but I can't figure out why it doesn't work.

Kind regards,

Michael

////////////////////////////////////////////////

This is more like the Architecture:

LIBRARY:
Imports System.IO

Imports System.Xml.Seri alization

Imports Stegosoft.Secur ity

Imports Stegosoft.Secur ity.DotFuscator

Imports System.Componen tModel

Imports System.Reflecti on

Namespace Settings

''' -----------------------------------------------------------------------------

''' Project : StegoSettings

''' Class : Settings.BaseSe ttings

'''

''' -----------------------------------------------------------------------------

''' <summary>

'''

''' </summary>

''' <remarks>

''' </remarks>

''' <history>

''' [Michael.Maes] 6/12/2003 Created

''' [Michael.Maes] 30/06/2004 Transform to better OO

''' </history>

''' -----------------------------------------------------------------------------

<Serializable() , _

SkipRenaming(), _

DebuggerStepThr ough()> _

Public MustInherit Class BaseSettings

#Region " Declarations "

Dim xmlSerializer As xmlSerializer

Friend Crypto As RijndaelSimple

Friend CallingAssembly As [Assembly]

Friend CallerClass As String

Dim TrackDirty As Boolean = False

Dim _IsDirty As Boolean = False

#End Region

#Region " Constructors "

Public Sub New()

' Set the Calling Assembly

CallingAssembly = Me.GetType.Asse mbly.GetCalling Assembly
Instanciate()
CallerClass = Me.GetType.Name .ToString.ToLow er()

Crypto = New RijndaelSimple

End Sub

Friend Sub Instanciate()

GetProductFamil y()

GetCompany()

End Sub

Private Function GetProductFamil y() As String

Dim t As Type = GetType(Assembl yDefaultAliasAt tribute)

Dim r() As Object = CallingAssembly .GetCustomAttri butes(t, False)

If IsNothing(r) Or r.Length = 0 Then

Return Nothing

Else

_ProductFamily = CType(r(0), AssemblyDefault AliasAttribute) .DefaultAlias

Return _ProductFamily

End If

End Function

Private Function GetCompany() As String

Dim t As Type = GetType(Assembl yCompanyAttribu te)

Dim r() As Object = CallingAssembly .GetCustomAttri butes(t, False)

If IsNothing(r) Or r.Length = 0 Then

Return Nothing

Else

_Company = CType(r(0), AssemblyCompany Attribute).Comp any

Return _Company

End If

End Function

#End Region

#Region " Properties "

Dim _ProductFamily As String = Nothing

Friend ReadOnly Property ProductFamily() As String

Get

If IsNothing(_Prod uctFamily) Then _ProductFamily = GetProductFamil y()

Return _ProductFamily

End Get

End Property

Dim _Company As String = Nothing

Friend ReadOnly Property Company() As String

Get

If IsNothing(_Comp any) Then _Company = GetCompany()

Return _Company

End Get

End Property

Public Overridable ReadOnly Property IsDirty() As Boolean

Get

Return _IsDirty

End Get

End Property

Protected Sub MarkDirty()

If TrackDirty Then _IsDirty = True

End Sub

Public Sub StartMarkingDir ty() 'Protected

TrackDirty = True

End Sub

#End Region

#Region " FileExists "

<Description("C hecks if the file exists on the Harddisk with the given Path.")> _

Public Function FileExists(ByVa l path As String, Optional ByVal user As String = Nothing) As Boolean

If Not path.EndsWith(" \") Then path += "\"

' If User is Undefined -> Set it to the Assembly-Name of the Calling Assembly

If user Is Nothing Then user = Me.ProductFamil y

If File.Exists(pat h + user + FilePrefix + CallerClass + ".xml") = True Then

Return True

Else

Return False

End If

End Function

#End Region

#Region " Load "

Public Overridable Function Load(ByVal path As String, Optional ByVal user As String = Nothing) As Object

Debug.WriteLine ("Public Overridable Function Load")

Return PerformDeserial ization(path, user)

End Function

Friend Function PerformDeserial ization(ByVal path As String, ByVal user As String) As Object

Debug.WriteLine ("PerformDeseri alization")

If Not path.EndsWith(" \") Then path += "\"

If user Is Nothing Then user = Me.ProductFamil y

If File.Exists(pat h + user + FilePrefix + CallerClass + ".xml") = True Then

Dim srFile As StreamReader = New StreamReader(pa th + user + FilePrefix + CallerClass + ".xml")

Dim t As Type

Dim pi As PropertyInfo()

Dim p As PropertyInfo

Try

xmlSerializer = New Xml.Serializati on.XmlSerialize r(Me.GetType())

Dim cls As Object

cls = xmlSerializer.D eserialize(srFi le)

t = cls.GetType

pi = t.GetProperties ()

For Each p In pi

If p.PropertyType. Equals(GetType( System.String)) Then

p.SetValue(cls, Crypto.DecryptS tring(CType(p.G etValue(cls, Nothing), String)), Nothing)

End If

Next

Return cls

Catch ex As Exception

Debug.WriteLine (ex.ToString)

MsgBox(ex.ToStr ing)

Finally

srFile.Close()

End Try

Else

Dim ClassType As Type = Me.GetType()

Return Activator.Creat eInstance(Class Type, True)

End If

End Function

#End Region

#Region " Persist "

Public Sub Persist(ByVal path As String, Optional ByVal user As String = Nothing)

If user Is Nothing Then user = Me.ProductFamil y

PerformSerializ ation(path, user)

End Sub

Private Sub PerformSerializ ation(ByVal path As String, ByVal user As String)

If Not path.EndsWith(" \") Then path += "\"

Dim FileName As String = path + user.ToLower + FilePrefix + CallerClass.ToL ower + ".xml"

Dim swFile As StreamWriter = New IO.StreamWriter (FileName)

Dim t As Type = Me.GetType()

Dim pi As PropertyInfo()

Dim p As PropertyInfo

pi = t.GetProperties ()

' Encrypt Strings

For Each p In pi

If p.PropertyType. Equals(GetType( System.String)) Then

p.SetValue(Me, Crypto.EncryptS tring(CType(p.G etValue(Me, Nothing), String)), Nothing)

End If

Next

' Save to Disk

xmlSerializer = New Xml.Serializati on.XmlSerialize r(t)

xmlSerializer.S erialize(swFile , Me)

swFile.Close()

End Sub

#End Region

End Class

End Namespace

*************** *********

Namespace Settings

''' -----------------------------------------------------------------------------

''' Project : StegoSettings

''' Class : Settings.TestDa ta

'''

''' -----------------------------------------------------------------------------

''' <summary>

''' This is "A" Demo-Class. In reality there are many classes like this, all inheriting from BaseSettings

''' </summary>

''' <remarks>

''' </remarks>

''' <history>

''' [Michael.Maes] 6/12/2003 Created

''' [Michael.Maes] 30/06/2004

''' </history>

''' -----------------------------------------------------------------------------

<Serializable() > Public Class TestData

Inherits BaseSettings

Public Sub New()

MyBase.New()

' CallingAssembly = Me.GetType.Asse mbly.GetCalling Assembly

' MyBase.Instanci ate()

End Sub

#Region " Load "

Public Shadows Function Load(ByVal path As String, Optional ByVal user As String = Nothing) As TestData

Try

StartMarkingDir ty()

Return DirectCast(Perf ormDeserializat ion(path, user), TestData)

Catch ex As Exception

Return Nothing

End Try

End Function

#End Region

Private _connectionName As String

Private _dataSource As String

Private _initialCatalog As String

Private _DataLibrary As String

Private _DataLibraryUrl As String

Private _password As String

Private _persistSecurit yInfo As Boolean = False

Private _userID As String

Public Property ConnectionName( ) As String

Get

Return _connectionName

End Get

Set(ByVal Value As String)

_connectionName = Value : MarkDirty()

End Set

End Property

Public Property DataLibrary() As String

Get

Return _DataLibrary

End Get

Set(ByVal Value As String)

_DataLibrary = Value : MarkDirty()

End Set

End Property

Public Property DataLibraryUrl( ) As String

Get

Return _DataLibraryUrl

End Get

Set(ByVal Value As String)

_DataLibraryUrl = Value : MarkDirty()

End Set

End Property

Public Property DataSource() As String

Get

Return _dataSource

End Get

Set(ByVal Value As String)

_dataSource = Value : MarkDirty()

End Set

End Property

Public Property InitialCatalog( ) As String

Get

Return _initialCatalog

End Get

Set(ByVal Value As String)

_initialCatalog = Value : MarkDirty()

End Set

End Property

Public Property Password() As String

Get

Return _password

End Get

Set(ByVal Value As String)

_password = Value : MarkDirty()

End Set

End Property

Public Property PersistSecurity Info() As Boolean

Get

Return _persistSecurit yInfo

End Get

Set(ByVal Value As Boolean)

_persistSecurit yInfo = Value : MarkDirty()

End Set

End Property

Public Property UserID() As String

Get

Return _userID

End Get

Set(ByVal Value As String)

_userID = Value : MarkDirty()

End Set

End Property

Public Function ConnectionStrin g() As String

Dim cn As String = _

"workstatio n id=" & SystemInformati on.ComputerName .ToString & ";" & _

"packet size=4096;" & _

"User ID=" & MyClass.UserID & ";" & _

"Password=" & MyClass.Passwor d & ";" & _

"data source=" & MyClass.DataSou rce & ";" & _

"persist security info=" & MyClass.Persist SecurityInfo & ";" & _

"initial catalog=" & MyClass.Initial Catalog

Return cn

End Function

End Class

End Namespace

*************** ***************

*************** ***************

EXE:

''' -----------------------------------------------------------------------------

''' <summary>

''' Just a test

''' </summary>

''' <remarks>

''' </remarks>

''' <history>

''' [Michael.Maes] 1/07/2004 Created

''' </history>

''' -----------------------------------------------------------------------------

Module StartUp

Sub Main()

Dim DataConnection As New Stegosoft.Setti ngs.TestData

DataConnection = DataConnection. Load("..\", "Jef")

Dim s As String = Nothing

s += "ConnectionName : " & DataConnection. ConnectionName & vbCrLf

s += "DataLibrar y: " & DataConnection. DataLibrary & vbCrLf

s += "DataLibraryUrl : " & DataConnection. DataLibraryUrl & vbCrLf

s += "DataSource : " & DataConnection. DataSource & vbCrLf

s += "InitialCatalog : " & DataConnection. InitialCatalog & vbCrLf

s += "Password: " & DataConnection. Password & vbCrLf

s += "PersistSecurit yInfo: " & DataConnection. PersistSecurity Info.ToString & vbCrLf

s += "UserID: " & DataConnection. UserID & vbCrLf

s += vbCrLf

s += "IsDirty: " & DataConnection. IsDirty.ToStrin g & vbCrLf

s += vbCrLf

' Changing Values => Object SHOULD become dirty (but it doesn't)

With DataConnection

..ConnectionNam e = "Jeff_BlaBlaBla "

..DataLibrary = "Jeff_DataLibra ry"

..DataLibraryUr l = "Jeff_DataLibra ryUrl"

..DataSource = "Jeff_DataSourc e"

..InitialCatalo g = "Jeff_InitialCa talog"

..Password = "Jeff_Passw ord"

..PersistSecuri tyInfo = True

..UserID = "Jeff_UserI D"

End With

s += "ConnectionName : " & DataConnection. ConnectionName & vbCrLf

s += "DataLibrar y: " & DataConnection. DataLibrary & vbCrLf

s += "DataLibraryUrl : " & DataConnection. DataLibraryUrl & vbCrLf

s += "DataSource : " & DataConnection. DataSource & vbCrLf

s += "InitialCatalog : " & DataConnection. InitialCatalog & vbCrLf

s += "Password: " & DataConnection. Password & vbCrLf

s += "PersistSecurit yInfo: " & DataConnection. PersistSecurity Info.ToString & vbCrLf

s += "UserID: " & DataConnection. UserID & vbCrLf

s += vbCrLf

s += "IsDirty: " & DataConnection. IsDirty.ToStrin g & vbCrLf

s += vbCrLf

'Explicitly trigger the dirty-checking (For Testing)

s += "StartMarkingDi rty: " & vbCrLf

DataConnection. StartMarkingDir ty()

With DataConnection

..ConnectionNam e = "BliBliBli"

End With

s += "ConnectionName : " & DataConnection. ConnectionName & vbCrLf

s += "DataLibrar y: " & DataConnection. DataLibrary & vbCrLf

s += "DataLibraryUrl : " & DataConnection. DataLibraryUrl & vbCrLf

s += "DataSource : " & DataConnection. DataSource & vbCrLf

s += "InitialCatalog : " & DataConnection. InitialCatalog & vbCrLf

s += "Password: " & DataConnection. Password & vbCrLf

s += "PersistSecurit yInfo: " & DataConnection. PersistSecurity Info.ToString & vbCrLf

s += "UserID: " & DataConnection. UserID & vbCrLf

s += vbCrLf

s += "IsDirty: " & DataConnection. IsDirty.ToStrin g

MsgBox(s)

DataConnection. Persist("..\", "Jef")

End

End Sub

End Module

Nov 20 '05 #7
Hi Michael,

I understand that you have three Assembly , A,B and C.
A has the method WhoIsCallme which calls GetCallingAssem bly
B inhertis A
C call the method WhoIsCallme.

I think in this way the behavior is by design, if you need to reach your
goal, you may try to override the function in the class B.

As for the second question,
I think why firsttime we change the DataConnection' s property, the IsDirty
is always false is because the TrackDirty is false.
I think we may try to change the code as below in the baseclass.

Dim _TrackDirty As Boolean = False
Public Property TrackDirty() As Boolean
Get
Return _TrackDirty
End Get
Set(ByVal Value As Boolean)
_TrackDirty = Value
End Set
End Property

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 20 '05 #8
Hi Peter,

I'm mailing you a test-project.

Regards,

Michael
Nov 20 '05 #9
Hi Michael,

Yes, the constructor of TestData will be called twice.
1. first time we new the testdata
2. we deserialized the object from the file

But the two constructors will construct two instance of testdata.
Dim DataConnection As New Settings.Settin gs.TestData
Dim bdc As Settings.Settin gs.TestData
bdc = DataConnection. Load(Path, User)
Console.WriteLi ne(Object.Refer enceEquals(Data Connection, bdc))

If we run the code above, we will find that the instance created by New and
the one created by Load are two different objects.
If you still have any concern, please feel free to let me know.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 20 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
11108
by: Marco Aschwanden | last post by:
Hi I checked the other day a module of mine with pylint. And for some function it told me, that I was using too many return-statements in my code... there were about 5 or 7 of them in my function. Through books I learned, that there should be only 1 return statement in a function. This makes for clear code - they said. I tried to stick to this principle for a very long time... ending up with deeper and deeper nested...
20
2339
by: Jakob Bieling | last post by:
Hi! I am using VC++ 7.1 and have a question about return value optimization. Consider the following code: #include <list> #include <string> struct test {
2
4667
by: Rhino | last post by:
I am trying to verify that I correctly understand something I saw in the DB2 Information Center. I am running DB2 Personal Edition V8.2.1 on Windows. I came across the following in the Info Center: To return a result set from a procedure to the originating application, use the WITH RETURN TO CLIENT clause. When WITH RETURN TO CLIENT is specified on a result set, no nested procedures can access the result set.
1
4675
by: Jack Addington | last post by:
I have a 3rd party object that fires an itemchanged event when someone edits some data on a form. This event has a custom eventArgs that has a field called ActionCode. In the code of the event, if you set this ActionCode to various values the control will respond in various ways (reject, reject change field, accept, etc). I am trying to understand exactly how that works as I am trying to extend the control and add more processing s...
4
1953
by: Noah Roberts | last post by:
The following code does VERY strange things in the debugger. Is there anything wrong with the following code, UB or anything else? #include <iostream> #include <exception> #include <stdexcept> int main() { int * parser;
14
20974
by: tshad | last post by:
Is there any difference between Return and Exit Sub? I have some code that uses both when I have an error in my Sub. Thanks, Tom
14
1939
by: Alexander Stoyakin | last post by:
Hello! Please advise on the following issue. I have a function which returns 1 or 0 in multiple branches, and it must perform the same code before each return, like this: int fun() { if (some code) { restore(param1,param2,param3,param4,param5); return 1;
13
2906
by: cppquester | last post by:
A colleague told me that there is a rule about good stype that a function in C++ should have only one point of return (ie. return statement). Otherwise there might be trouble. I never heard about it and doubt it. Anybody heard of it? What would be the advantage? Regards, Marc Example:
6
1830
by: exander77 | last post by:
I am quite new to c++, about half of a year. I juct wonder, why such code is not possible: int chlen(char * ar) { for(int i=0;ar||return i;i++); } In my opinion, it would be much "cuter" than this: int chlen(char * ar) {
4
2480
by: barcaroller | last post by:
I am trying to adopt a model for calling functions and checking their return values. I'm following Scott Meyer's recommendation of not over-using exceptions because of their potential overhead. Here's the approach I'm currently looking at. I throw exceptions only from constructors. Destructors, of course, do not throw exceptions. All other functions return a signed integer. The values are all stored in one large header file (as...
0
8788
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9290
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9061
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9001
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7925
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6615
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
3151
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2508
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2097
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.