The problem is, that you copy the references (you might think the values) of the attributes to your list. So the entry in your list is not the setter of your class-attribute but a reference to it's value in memory.

You might try something like

1
let attributes = [(fun s -> myClass.a <- s); (fun s -> myClass.b <- s); (fun s -> myClass.b <- s)]

and then just

1
attributs |> List.iteri (fun index attrib -> attrib (guibox.[index].Text) )

I did not check if this works exactly this way, but it should (now the list is not of type (string list) but of type ((string -> unit) list) )

Of course you can think of some nicer syntax and/or using reflection ... have fun

By on 10/12/2010 2:09 AM ()

The problem is, that you copy the references (you might think the values) of the attributes to your list. So the entry in your list is not the setter of your class-attribute but a reference to it's value in memory.

You might try something like

1
let attributes = [(fun s -> myClass.a <- s); (fun s -> myClass.b <- s); (fun s -> myClass.b <- s)]

and then just

1
attributs |> List.iteri (fun index attrib -> attrib (guibox.[index].Text) )

I did not check if this works exactly this way, but it should (now the list is not of type (string list) but of type ((string -> unit) list) )

Of course you can think of some nicer syntax and/or using reflection ... have fun

I also think so.

_________________
Watch Megamind Online Free

By on 11/4/2010 12:32 AM ()

Hi,

thanks for the quick reply.

I'm about to try your suggestion.

Regards

Mark

By on 10/12/2010 2:12 AM ()

Yes that seems to be working fine (I can't test it fully yet because I have a lot more to write but the compiler is happy now!).

It's actually quite straightforward now you've explained it.

(Assuming I'm reading this right)..
I have a list of functions which assign values to a specific attribute. I then iterate through that list applying each function to the respective textbox value.

By on 10/12/2010 2:27 AM ()

yep - that was the indent (of course you apply the textbox-text to the function but thats a minor detail ;)

By on 10/12/2010 2:29 AM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper