Jump to content
  • Revista PROGRAMAR: Já está disponível a edição #60 da revista programar. Faz já o download aqui!

Sign in to follow this  
fLaSh_PT

Carregando objectos dinamicamente

Recommended Posts

fLaSh_PT

Simples função, mas muito útil para carregar objectos dinamicamente.

    ''' <summary>
    ''' Carrega um objecto dinamicamente.
    ''' </summary>
    Public Function GetDynamicallyObject(ByVal sName As String, _
                                Optional ByVal oArgs() As Object = Nothing) As Object
	' Obtem o namespace da aplicação.
        Dim sAssemblyName As String = [Assembly].GetEntryAssembly().GetName.Name.Replace(" ", "_")
	' Obtem o tipo de objecto
        Dim oType As Type = Type.GetType(sAssemblyName & "." & sName)
	' Activa o objecto
	If oType IsNot Nothing Then
		Return Activator.CreateInstance(oType, oArgs)
	ELse
		Return Nothing
	End If
    End Function

Exemplo:

Dim f as Form = GetDynamicallyObject("Form1")


Making the impossible possible and pwing the world on db at a time.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.