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 9008763
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T02:01:13+00:00 2026-06-16T02:01:13+00:00

I’m doing a project called 2dShapeEditor where you are supposed to be able to

  • 0

I’m doing a project called “2dShapeEditor” where you are supposed to be able to create, click and drag different kind of shapes on a form. At the stage of the project I am at right now, i need to determine what kind of type my targeted rectangle is. It’s initialized as an “Option” but can through a “hittest” change to the specific rectangle that is clicked.

I will then apply my move method to this rectangle making it move with the mouse.

My type RectangleZ

type RectangleZ(x:int, y:int)= 
  let mutable thisx = x
  let mutable thisy = y
  let mutable thiswidth = 50
  let mutable thisheight = 20
  let brush = new SolidBrush(Color.Black)
  member obj.x with get () = thisx and set x = thisx <- x
  member obj.y with get () = thisy and set y = thisy <- y
  member obj.width with get () = thiswidth and set width = thiswidth <- width
  member obj.height with get () = thisheight and set height = thisheight <- height
  member obj.thisColor = Color.FromArgb(167, 198, 253)
  member obj.draw(paper:Graphics) = paper.FillRectangle(brush, thisx, thisy, 50, 20)
  member obj.ShapeType = "Rectangle"

My hittest method:

let rec getShape (e:MouseEventArgs) (inputl:List<RectangleZ>) = match inputl with 
                                                               |[] -> None
                                                               |s::tail->if(((e.X >= s.x) && (s.x <= (s.x + s.width))) && ((e.Y >= s.y) && (e.Y <= (s.y + s.height)))) then Some(s) else getShape e tail //Some(s)

My targeted rectangle look like this:

let mutable targetedRec = None 

My “Move()” method looks like this:

let Move (e:MouseEventArgs) = if(targetedRec = None) then None else targetedRec.Value.x <- e.X
                                                                    targetedRec.Value.y <- e.Y

The “Move()” method gives me the error: “Lookup on object of indeterminate type based on information prior to this
program point. A type annotation may be needed prior to this program to constrain the type of the object. This may allow the lookup to be resolved.”

And yes, the compiler gives me a hint of what’s wrong and how to fix it, i’ve tried with matching, if statements, I simply don’t understand what’s wrong and how to fix it. If I remove the Option type of the targetedRec and just put it as a type of “RectangleZ” alot of my project will fail because i can’t leave blank if statements. Any suggestions?

  • 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-06-16T02:01:14+00:00Added an answer on June 16, 2026 at 2:01 am

    What type is inferred for ‘targetedRec’? (You can tell by hovering the mouse over it and looking at the Intellisense tooltip.)

    From what you’ve posted, the F# compiler is only able to infer the type of ‘targetedRec’ as 'a option — that is, the compiler knows it’s an Option (because you’ve assigned None to it), but it can’t tell what the type parameter of the option is supposed to be. Then, you see the error in your Move method because the compiler can’t tell what type the x and y fields belong to.

    This is pretty easy to fix though — just add a type annotation to your declaration for targetedRec, like so:

    let mutable targetedRec : RectangleZ option = None
    

    That alone should fix the problem, but you can clean up your Move method a bit too by using pattern matching instead of manually checking the Value property:

    let Move (e : MouseEventArgs) =
        match targetedRec with
        | None -> ()
        | Some targetedRec ->
            targetedRec.x <- e.X
            targetedRec.y <- e.Y
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
Basically, what I'm trying to create is a page of div tags, each has
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I've tracked down a weird MySQL problem to the two different ways I was
I have a text area in my form which accepts all possible characters from
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm trying to create an if statement in PHP that prevents a single post
Let's say I'm outputting a post title and in our database, it's Hello Y&#8217;all
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function

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.