W
wisenow
Unregistered / Unconfirmed
GUEST, unregistred user!
定义<br> TShareRec = record<br> n: integer;<br> m: integer;<br> //a: string[10];<br> end;<br> TRecArr = array of TShareRec;<br>声明<br> hMap: THandle;<br><br>以下程序在同一程序中Button4Click可以正确执行<br>当把Button4Click代码写到另外的程序时出错, 各位帮忙了,多谢!<br>procedure TForm1.Button3Click(Sender: TObject);<br>var<br> Data: ^TRecArr;<br> a: TRecArr;<br>begin<br> SetLength(a, 3);<br> a[0].m := 1; a[0].n := 2; //a[0].a := 'a';<br> a[1].m := 3; a[1].n := 4; //a[1].a := 'b';<br> a[2].m := 5; a[2].n := 6; //a[2].a := 'c';<br> hMap := CreateFileMapping(DWord($FFFFFFFF), nil, PAGE_READWRITE, 0, 2 * SizeOf(TRecArr), pchar('SHARE_HANDLE'));<br> Data := MapViewofFile(hMap, FILE_MAP_WRITE, 0, 0, 0);<br> Data^ := a;<br> UnMapViewofFile(Data);<br>end;<br><br>procedure TForm1.Button4Click(Sender: TObject);<br>var<br> hRMap: THandle;<br> Data: ^TRecArr;<br> N: integer;<br>begin<br> hRMap := CreateFileMapping(DWORD($FFFFFFFF), nil, PAGE_READONLY, 0, 1, pchar('SHARE_HANDLE'));<br> Data := MapViewofFile(hRMap, FILE_MAP_READ, 0, 0, 0);<br> try<br> Memo1.Lines.Add(IntToStr(Low(Data^)) + '--' + IntToStr(High(Data^)));<br> for n := Low(Data^) to High(Data^) do<br> Memo1.Lines.Add(IntToStr(Data^[n].m) + ':' + IntToStr(Data^[n].n)); //+ //Data^[n].a);<br> finally<br> UnMapViewofFile(Data);<br> CloseHandle(hRMap);<br> end;<br>end;