句柄调用时报内存错误(100)

  • 主题发起人 主题发起人 kunwyf12345
  • 开始时间 开始时间
K

kunwyf12345

Unregistered / Unconfirmed
GUEST, unregistred user!
我定义了一个myoutputtype myoutput=class(tpanel)CMyOutput:array [0..MAXVIEWNUM-1] of myoutput;窗体创建时创建CMyOutput for i:=0 to combobox1.itemindex do begin for j:=0 to combobox1.itemindex do begin CMyOutput[m]:=MYOUTPUT.create(Self); CMyOutput[m].Parent:=frmmain; CMyOutput[m].Height:=panel2.Height div (combobox1.itemindex+1); CMyOutput[m].width:=panel2.width div (combobox1.itemindex+1); CMyOutput[m].top:=panel2.top+(i )*CMyOutput[m].Height ; CMyOutput[m].left:=panel2.left+(j)*CMyOutput[m].width; CMyOutput[m].Caption:=inttostr(m); CMyOutput[m].BevelInner:=bvlowered; CMyOutput[m].BevelWidth:=2; CMyOutput[m].PopupMenu:=popupmenu1; CMyOutput[m].OnClick:=CMyOutput[m]._ButtonClick; CMyOutput[m].OnMouseDown:=CMyOutput[m]._MouseDown; cmyoutput[m].m_iPlayhandle:=-1; CMyOutput[m].setindexi(m); inc(m); end; end;点按钮时运行下句if (CMyOutput[icount].Handle >= 0) thenCMyOutput[icount].StartNet(@selipinfo[icount]);偶尔就会跳转到controls单元的procedure TWinControl.HandleNeeded;begin if FHandle = 0 then然后报内存错误如果把if (CMyOutput[icount].Handle >= 0) then去掉,直接运行下句也是偶尔正确,偶尔在StartNet的事件内跳到system单元的procedure _HandleFinally;的 MOV EAX,[ESP+4]行,然后报内存错误为什么啊?CMyOutput在formshow的时候就创建了,为什么取handle时有时候就报错,有时候没问题啊
 
CMyOutput[m]:=MYOUTPUT.create(Self); 这里 m 是如何初始化的?if (CMyOutput[icount].Handle >= 0) thenCMyOutput[icount].StartNet(@selipinfo[icount]);这里 icount 是如何初始化的?
 
m从0开始,icount也是,每次都是icount=1时报错,可是m的值每次最后都是3
 
从你的代码里看不出来m的变化,似乎m一直等于0,[:(]
 
有变化啊,inc(m);了啊
 
for循环里只要执行一下就加了啊
 
StartNet 里面代码呢?
 
procedure myoutput.StartNet(ipinfo: PIP_INFO);var dwErr:dword; csEventTime:array [0..EVENTNUM-1] of String ; csEventInfo:array [0..EVENTNUM-1] of String ; iEventPos:integer; boolreturn:boolean; dwordint:dword; pstr:pointer;begin //startnet fillMemory(@user,100,0); fillMemory(@password,100,0); m_iPlayhandle:=-1; if(m_iPlayhandle <>-1) then begin if(g_bShareSound=true) then begin boolreturn:=NET_DVR_CloseSoundShare(m_iPlayhandle); end; if(NET_DVR_StopRealPlay(m_iPlayhandle)=false) then begin showmessage('NET_DVR_StopRealPlay 失败 m_iPlayhandle = '+inttostr(m_iPlayhandle)); end; end; m_bNeedjudge := FALSE; g_nNetDelay:=2; playstru.hPlayWnd :=self.Handle; //hwnd1; playstru.lChannel := ipinfo.m_iChannel; playstru.lLinkMode := ipinfo.m_dwProtocol; if(ipinfo.m_dwMultiIPvalue = 0) then pstr:=strcopy(@multiipaddress,pchar('')) else multiipaddress:=format('%s',[ipinfo.m_csMultiIP]); playstru.sMultiCastIP := @multiipaddress; iServerPort := ipinfo.m_wServerport; m_iPlayhandle:= NET_DVR_RealPlay(ipinfo.m_lServerID, @playstru); if(m_iPlayhandle = -1) then begin dwErr := NET_DVR_GetLastError(); ipaddress:=format('%s',[ipinfo.m_csIP]); sTemp:=Format('访问IP:%s 通道%d 连接启动失败 dwErr = %d',[ipaddress,playstru.lChannel, dwErr]); showmessage(sTemp); csEventTime[iEventPos]:=Format('%04d-%02d-%02d %02d:%02d:%02d', [yearof(time), monthof(time), dayof(time), Hourof(time),Minuteof(time), Secondof(time)]); csEventInfo[iEventPos]:=Format('%s', [sTemp]); iEventPos:=iEventPos+1; if(iEventPos >= EVENTNUM) then iEventPos := 0; end else begin dwordint:=net_dvr_getlasterror(); case g_nNetDelay of 0: boolreturn:=NET_DVR_SetPlayerBufNumber(m_iPlayhandle, 1); 1: boolreturn:=NET_DVR_SetPlayerBufNumber(m_iPlayhandle, 6); 2: boolreturn:=NET_DVR_SetPlayerBufNumber(m_iPlayhandle, 15); 3: boolreturn:=NET_DVR_SetPlayerBufNumber(m_iPlayhandle, 30); 4: boolreturn:=NET_DVR_SetPlayerBufNumber(m_iPlayhandle, 45); else boolreturn:=NET_DVR_SetPlayerBufNumber(m_iPlayhandle, 15); end; boolreturn:=NET_DVR_ThrowBFrame(m_iPlayhandle,1); boolreturn:=NET_DVR_SetRealDataCallBack(m_iPlayhandle, myRealDataCallBack ,m_iPlayhandle); m_dwDVRIP:=ipinfo.m_dwIPvalue; m_lServerID:=ipinfo.m_lServerID; m_csIP:=ipinfo.m_csIP; m_iChannel:=playstru.lChannel; m_bNeedjudge:=TRUE; end;end;
 
我发现把icount去掉,直接写if (CMyOutput[0].Handle >= 0) thenCMyOutput[0].StartNet(@selipinfo[0]);if (CMyOutput[1].Handle >= 0) thenCMyOutput[1].StartNet(@selipinfo[1]);这样就没问题,可是我的icount showmessage了啊,显示是对的啊,为什么放到CMyOutput[icount]里就不对了呢?
 
还有CMyOutput[0]只能解决一时,这个根本还是要循环的,可是这个循环现在要怎么改啊?
 
从你贴出来的部分代码看不出来,不过估计问题还是越界访问或者访问未创建的对象,释放已释放的对象等原因,你跟踪一下看看吧。
 
那个定死了也出错,好像CMyOutput[1]根本没创建一样,我就在创建中加了showmessage(inttostr(m));现在不出错了,我哪块弄错了啊?
 
我也不知道,少用全局变量和动态类型,对于所有变量都显式初始化,自己创建的对象和自己申请的内存由自己负责释放,估计这样问题能少一些
 
谢谢,我找到原因了, user和password是全局变量,我用下面两句把全局清零就把新建的CMyOutput给清没了fillMemory(@user,100,0);fillMemory(@password,100,0);
 
后退
顶部