Change item value of referenced array in clousure
Look, I've got some method where I try to check if value is changed and write it if it is changed but so , I need to remember wich values had changed and here is a problem, I can't set changed flag because I don开发者_如何转开发't know how to cheange ref item and I can't use mutable there.
member X.qArchive() =
//let mutable rememberer = [for d in db.AlarmDictionaries -> d.ID, false].ToArray()
let rememberer = ref ( [for d in db.AlarmDictionaries -> d.ID, false].ToArray() )
seq {for a in db.ArchiveDescretes do
let i = ref 0
for r in !rememberer do
if a.ID = fst r && snd r = false then
rememberer.[(!i)] := fst r, true // Error
//rememberer.[(!i)] <- fst r, true // Error
for c in db.AlarmDictionaries do
if (c.ID = a.ID) then
yield a.Date, c.Message, a.Value
i := !i + 1 } |> Array.ofSeq
also if you know how can I realize this idea with some better way I will thank you too.
here is my wicked variant :
member X.qArchive() =
seq { let metarememberer = ref ( [for d in db.AlarmDictionaries -> d.ID, false].ToArray() )
let rememberer = ref ( [for d in db.AlarmDictionaries -> d.ID, false].ToArray() )
for a in db.ArchiveDescretes do
let i = ref 0
for r in !metarememberer do
if a.ID = fst r && snd r = false then
(!metarememberer).[!i] <- fst r, true
for c in db.AlarmDictionaries do
if c.ID = a.ID && c.Value = a.Value then
let j = ref 0
for rm in !rememberer do
if a.ID = fst rm then
(!rememberer).[!j] <- fst rm, a.Value
j := !j + 1
yield a.Date, c.Message
else
let j = ref 0
for rm in !rememberer do
if a.ID = fst rm && a.Value <> snd rm then
(!rememberer).[!j] <- fst rm, a.Value
for c in db.AlarmDictionaries do
if c.ID = a.ID && c.Value = a.Value then
yield a.Date, c.Message
j := !j + 1
i := !i + 1
} |> Array.ofSeq
Update : After all my variant doesn't work. Something wrong here ... I can see same event 2 times, I need to see it only when value is changed so that means I can't see same event 2 times.
what about this one?
(!rememberer).[!i] <- fst r, true
精彩评论