Last change
on this file since 231 was 230, checked in by イグトランス (egtra), 18 years ago |
GCHandleTestの追加、全てのテスト処理を関数に入れる
|
File size:
1.4 KB
|
Rev | Line | |
---|
[203] | 1 | ' Classes/System/Runtime/InteropServices/GCHandle.ab
|
---|
| 2 |
|
---|
| 3 | #require <Classes/System/Collections/ArrayList.ab>
|
---|
| 4 |
|
---|
| 5 | Class GCHandle
|
---|
| 6 | Public
|
---|
| 7 | Function Target() As Object
|
---|
| 8 | Dim pobj = VarPtr(handle) As *Object
|
---|
| 9 | Return pobj[0]
|
---|
| 10 | End Function
|
---|
| 11 |
|
---|
| 12 | Sub Target(obj As Object)
|
---|
| 13 | allocated.Add(obj)
|
---|
[230] | 14 | handle = VarPtr(obj) 'ObjPtr
|
---|
[203] | 15 | End Sub
|
---|
| 16 |
|
---|
| 17 | Const Function IsAllocated() As Boolean
|
---|
| 18 | Retrun handle <> 0
|
---|
| 19 | End Function
|
---|
| 20 |
|
---|
| 21 | Static Function Alloc(obj As Object) As GCHandle
|
---|
| 22 | Alloc = New GCHandle
|
---|
| 23 | Alloc.Target = obj
|
---|
| 24 | End Function
|
---|
| 25 |
|
---|
| 26 | Sub Free()
|
---|
| 27 | allocated.Remove(Target)
|
---|
| 28 | handle = 0
|
---|
| 29 | End Sub
|
---|
| 30 |
|
---|
| 31 | Static Function ToIntPtr(h As GCHandle) As LONG_PTR
|
---|
[223] | 32 | Return h.handle As LONG_PTR
|
---|
[203] | 33 | End Function
|
---|
| 34 |
|
---|
| 35 | Static Function FromIntPtr(ip As LONG_PTR) As GCHandle
|
---|
| 36 | FromIntPtr = New GCHandle
|
---|
[223] | 37 | FromIntPtr.handle = ip As VoidPtr
|
---|
[203] | 38 | End Function
|
---|
| 39 |
|
---|
| 40 | Override Function GetHashCode() As Long
|
---|
| 41 | Return _System_HashFromPtr(handle)
|
---|
| 42 | End Function
|
---|
| 43 |
|
---|
| 44 | Function Equals(y As GCHandle) As Boolean
|
---|
| 45 | Return handle = y.handle
|
---|
| 46 | End Function
|
---|
| 47 |
|
---|
[208] | 48 | Function Operator == (y As GCHandle) As Boolean
|
---|
[203] | 49 | Return Equals(y)
|
---|
| 50 | End Function
|
---|
| 51 |
|
---|
| 52 | Function Operator <> (y As GCHandle) As Boolean
|
---|
| 53 | Return Not Equals(y)
|
---|
| 54 | End Function
|
---|
| 55 |
|
---|
[208] | 56 | Override Function ToString() As String
|
---|
| 57 | Return "System.Runtime.InteropServices.GCHandle"
|
---|
| 58 | End Function
|
---|
| 59 |
|
---|
[203] | 60 | 'Private
|
---|
| 61 | Sub GCHandle()
|
---|
| 62 | End Sub
|
---|
| 63 |
|
---|
| 64 | Private
|
---|
| 65 | handle As VoidPtr
|
---|
| 66 |
|
---|
| 67 | Static allocated As ArrayList
|
---|
| 68 | End Class
|
---|
Note:
See
TracBrowser
for help on using the repository browser.