Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 753245
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T14:52:30+00:00 2026-05-14T14:52:30+00:00

The application that I am working on has a generic Parent Form called RSChild,

  • 0

The application that I am working on has a generic Parent Form called RSChild, that is used to perform some operations depending on whether or not the control that is contained within it is in a MdiTabManager or inside of its own modal form. Then the actual User Controls contained within Inherit from a Interface Called ObjectEdit (Objects that we allow to be edited). At a point in my code I am doing this.

Public Function doesTabExist(ByVal id As Integer, ByVal recordType As Enums.eRecordType) As Boolean
        Dim alikePages As Object = (From tabs In DirectCast(Control.FromHandle(MainForm.SharedHandle), MainForm).XtraTabbedMdiManager1.Pages Where DirectCast(tabs.MdiChild, RSChild).RSObject.RecordType = recordType Select tabs)
        For Each page As DevExpress.XtraTabbedMdi.XtraMdiTabPage In alikePages
            Select Case recordType
                Case Enums.eRecordType.Doctor
                    If id = DirectCast(castTabPageToRSChild(page).RSObject, UI.Doctor).ID Then
                        pageToActive(page)
                        Return True
                    End If
'rest of the cases so the case block is repeated 10 times'

End Function

And my castTabPageToRSChild(page) is a lambda function as Such

 Dim castTabPageToRSChild As Func(Of DevExpress.XtraTabbedMdi.XtraMdiTabPage, RSChild) = Function(page) DirectCast(page.MdiChild, RSChild)

So my Question is, I have about 10 case statements, all because I can’t seem to find a way to use reflection to get the underlying Type of the RSObject Object. So I have the whole If block repeated over and over. I tried doing castTabPageToRSChild(page)RSObject.GetType and using that in the DirectCast and I also tried creating another object that was separate from that and doing the same thing.

My code works as intended I’m just trying to see if there is a manner in which I didn’t have a lot of replicated code. My vision would be to do something like

For Each page As XtraMdiTabPage In alikePages
    If id = DirectCast(castTabPageToRSchild(page).RSObject, castTabPageToRSChild(page).RSObject.GetType).Id Then Return True
Next

However I have a feeling this is not possible due to the behavior of DirectCast.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T14:52:30+00:00Added an answer on May 14, 2026 at 2:52 pm

    Use TryCast instead. It returns Nothing if the object is not of the expected type.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working to develop an application that has to query at some time, a
I am working on an application that has been edited by various programmers over
I'm working on an application that has a read-only database shipped with it. The
I'm working on a web application that has a lot to download (javascript, images,
I'm currently working in an application that has to navigate a webpage and recollect
I am currently working on an application that has different permissions/users for the local
I am working with your typical three layered application that has a presentation layer,
I'm working on a server in a distributed application that has browser clients and
I am working on a simple app tab-bar based application that has two views.
I'm currently working on a large and old C++ application that has had many

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.