'
Code:
#Compile Exe 'Ptrs3.bas #Dim All #Include "Win32Api.inc" ' Type Person szName As Asciiz*24 dwAge As Dword dblIncome As Double End Type ' ' Sub OutputRoutine(strFileName As String) Local pSomebody As Person Ptr Local pSomeone As Person Ptr Local pBody As Person Ptr Local dwPtr As Dword Ptr Local Someone As Person Local blnFree As Long Register i As Long Local fp As Integer ' fp=Freefile Open strFileName For Random As #fp Len=Len(Person) pSomeone=HeapAlloc(GetProcessHeap(),%HEAP_ZERO_MEMORY,sizeof(Person)*4) Print "pSomeone = "pSomeone : Print If pSomeone Then Print "Some of My Favorite Frenchmen" Print Print " i Varptr(@pSomeone[i]) @pSomeone[i].szName @pSomeone[i].dwAge @pSomeone[i].dblIncome" Print "=============================================================================================" For i=0 To 3 Get #fp,i+1,Someone Poke$ Asciiz, Varptr(@pSomeone[i]), Someone.szName @pSomeone[i].dwAge=Someone.dwAge @pSomeone[i].dblIncome=Someone.dblIncome Print i; _ Tab(5)Varptr(@pSomeone[i]); _ Tab(28)@pSomeone[i].szName; _ Tab(58)@pSomeone[i].dwAge; _ Tab(75)@pSomeone[i].dblIncome Next i Print dwPtr=HeapAlloc(GetProcessHeap(),%HEAP_ZERO_MEMORY,16) Print Print "dwPtr = "dwPtr Print Print " i Varptr(@dwPtr[i]) @dwPtr[i] @pSomeone[i].szName @pSomeone[i].dwAge @pSomeone[i].dblIncome" Print "======================================================================================================" If dwPtr Then For i=0 To 3 @dwPtr[i]=Varptr(@pSomeone[i]) [email protected][i] Print i; _ Tab(5)Varptr(@dwPtr[i]); _ Tab(24)@dwPtr[i]; _ Tab(37)@pSomebody.szName; _ Tab(60)@pSomebody.dwAge; _ Tab(84)@pSomebody.dblIncome Next i Print:Print Print " i pBody @dwPtr[i] @@pBody.szName @@pBody.dwAge @@pBody.dblIncome" Print "==============================================================================" For i=0 To 3 pBody=Varptr(@dwPtr[i]) Print i; _ Tab(5)pBody; _ Tab(14)@dwPtr[i]; _ Tab(26)@@pbody.szName; _ Tab(50)@@pbody.dwAge; _ Tab(64)@@pbody.dblIncome Next i blnFree=Abs(IsTrue(HeapFree(GetProcessHeap(),0,pSomeone))) Print Print "blnFree="blnFree End If Close #fp blnFree=Abs(IsTrue(HeapFree(GetProcessHeap(),0,dwPtr))) Print "blnFree="blnFree End If End Sub ' ' Function PBMain() As Long Local strFile As String Local per() As Person Register i As Long Local fp As Integer ' Redim per(3) As Person per(0).szName="Alexis Detocqueville" '1st person per(0).dwAge=24 per(0).dblIncome=45654.67 per(1).szName="Emile Durkheim " '2nd person per(1).dwAge=48 per(1).dblIncome=47453.12 per(2).szName="Frederic LePlay " '3rd person per(2).dwAge=25 per(2).dblIncome=93654.67 per(3).szName="Rene Descartes " '4th person per(3).dwAge=67 per(3).dblIncome=45654.67 Print "SizeOf(Person)="SizeOf(Person) strFile="Data.dat" fp=Freefile Open strFile For Random As #fp Len=Len(Person) For i=0 To 3 Put #fp,i+1,per(i) Next i Close #fp Call OutputRoutine(strFile) Waitkey$ ' PBMain=0 End Function
Code:
'SizeOf(Person)= 36 'pSomeone = 1282512 ' 'Some of My Favorite Frenchmen ' ' i Varptr(@pSomeone[i]) @pSomeone[i].szName @pSomeone[i].dwAge @pSomeone[i].dblIncome '============================================================================================= ' 0 1282512 Alexis Detocqueville 24 45654.67 ' 1 1282548 Emile Durkheim 48 47453.12 ' 2 1282584 Frederic LePlay 25 93654.67 ' 3 1282620 Rene Descartes 67 45654.67 ' ' 'dwPtr = 1282704 ' ' i Varptr(@dwPtr[i]) @dwPtr[i] @pSomeone[i].szName @pSomeone[i].dwAge @pSomeone[i].dblIncome '====================================================================================================== ' 0 1282704 1282512 Alexis Detocqueville 24 45654.67 ' 1 1282708 1282548 Emile Durkheim 48 47453.12 ' 2 1282712 1282584 Frederic LePlay 25 93654.67 ' 3 1282716 1282620 Rene Descartes 67 45654.67 ' ' ' i pBody @dwPtr[i] @@pBody.szName @@pBody.dwAge @@pBody.dblIncome '============================================================================== ' 0 1282704 1282512 Alexis Detocqueville 24 45654.67 ' 1 1282708 1282548 Emile Durkheim 48 47453.12 ' 2 1282712 1282584 Frederic LePlay 25 93654.67 ' 3 1282716 1282620 Rene Descartes 67 45654.67 ' 'blnFree= 1 'blnFree= 1
Fred
"fharris"+Chr$(64)+"evenlink"+Chr$(46)+"com"
Leave a comment: