小弟引用下面代码调用Form3窗体,第一次调用成功打开Form3后关闭,再次调用就出错了
var
  Form3:TForm;//全局变量procedure TForm2.Button13Click(Sender: TObject);
begin
   if not Assigned(Form3) then
   Form3:=TForm3.Create(application);
   try
    Form3.ShowModal;
   finally
    Form3.Release;
   end;
end;错误提示信息为:Project wu.exe raised exception class EAccessViiolation with message'Access violation at address 00000000.Read of address 00000000'.Process stopped.Use Step or Run to continue.请个位大侠帮忙解决一下

解决方案 »

  1.   

    Form3.Release;
    改成
    form3.free;
    form3 := nil;
      

  2.   


    刚才我也是这么想得,但是查了查发现procedure TCustomForm.Release;
    begin
    PostMessage(Handle, CM_RELEASE, 0, 0);
    end;
    procedure CMRelease(var Message: TMessage); message CM_RELEASE;
    procedure TCustomForm.CMRelease;
    begin
    Free; //最后还是free; 
    end;
      

  3.   

    先试着把这两句统一看看
    Form3:TForm3;//全局变量
    Form3:=TForm3.Create(application);
     
      

  4.   

    30 此处是消息类型转换   g_stSendToPnPTxTab.pstTxTab  301  pstMsg->enType 302
    pstMsg->uwSubSeq 303
    VOID ChangePnPMsgType(PPNP_Report_MSG  pstMsg, UINT16 uwSeq){ CHECK;
    if ( TO_PNP_SYNC_TYPE == 301[uwSeq].ucMsgType ){302 = PNP_RESP_SYNC_TYPE;303 = 301[uwSeq].uwSubSeq;
    }else if ( TO_PNP_ASY_TYPE == 301[uwSeq].ucMsgType ){302 = PNP_RESP_ASY_TYPE;
    303 = 301[uwSeq].uwSubSeq;}else if ( TO_PNP_305_TYPE == 301[uwSeq].ucMsgType ) 
    {302 = PNP_RESP_305_TYPE;303 = 301[uwSeq].uwSubSeq;}else{; }}
    31 在发送控制表查找EMUA消息单元  pstMsg->ulResId 311  pstMsg->uwCmd 312
    UINT32 FindEMUATxPos(PPNP_Report_MSG pstMsg, UINT16 *puwIndex)
    {UINT32 i = 0;CHECK;for ( i = 0 ; i < g_stSendToPnPTxTab.ucTabSize; i++ )
    {/* EMUA不比较握手字,因为EMUA不回握手字 */if (  (CCU_TRUE == 301[i].ucIsUsed)
    &&(CCU_OK == CompareResId(301[i].ulResId, 311))&&((UINT8)301[i].uwCmd   == (UINT8)312) )
    {*puwIndex = (UINT16)i;221;}}return CCU_ERR_MPI_UNMATCH_REQ;}
    32 处理seq超表情况的消息  return CCU_ERR_MPI_BUFFER_OVERFLOW 322
    CCU_NULL_WORD 323
    UINT32 ProcOverFlowSeq(PPNP_Report_MSG  pstMsg, UINT16 *puwNetSeq)
    {PNP_Report_MSG stMsg = {0};UINT16 uwSeq = 323; UINT32 ulRet = CCU_ERR;
    EMU_PROTOCOL_TYPE  enType =  EMU_INVILID_TYPE;CHECK;PNP_IsEMUAResID(311, &enType);
    if (EMUA_PROTOL_TYPE == enType){ulRet = FindEMUATxPos(pstMsg, &uwSeq);
    /* 如果找不到对应单元,但命令字是EMUA的告警命令,是主动告警,上报 */
    if ( (CCU_OK != ulRet)&&(EMUA_ALARM_CMD == 312 ))
    {302 = PNP_RESP_ALARM_TYPE;}else if(CCU_OK == ulRet) /* 找到了,按通常消息处理 */
    {CCU_MemCpy((UINT8*)&stMsg, (UINT8*)pstMsg, (INT32)sizeof(PNP_Report_MSG));
    ChangePnPMsgType(&stMsg, uwSeq);pstMsg->uwSeq    = uwSeq;
    302   = stMsg.enType;*puwNetSeq       = 301[uwSeq].uwNetSeq;303 = stMsg.uwSubSeq;                
    if(0xcffb == 312){312 = 0xe1fb;}}else{322; }}else /* 如果是主动告警,上报 */
    {if ( CCU_TRUE == IsAlarmCmd( 312 ) ){302 = PNP_RESP_ALARM_TYPE;}else{ 322;} }  221;}
      

  5.   

    33 回送数据到发送控制表  pstMsg->aucCmdData 330  pstMsg->ulLen 331
    CCU_NULL_BYTE 332 CCU_485CMD_RESPONSE_HEADLENGTH 333
    UINT32 PutDataToPnPTxTab(PPNP_Report_MSG       pstMsg, UINT16 *puwNetSeq){
    UINT16 uwSeq = 323;UINT8  ucCmd = 332;BOOL   bFlag = CCU_FALSE;CHECK;uwSeq = pstMsg->uwSeq; ucCmd = (UINT8)312;
    /* 注册命令不通过消息回调上报,滤除 */CHECK_PARA_RTN_VALUE(ucCmd, CMD_REGISTER, CCU_ERR_MPI_INVALID_PARAMS);  
    /* 当seq超出表范围时,可能是EMUA消息或部件主动告警消息,上报 */
    if ( uwSeq >= TO_PNP_TAB_SIZE ){return(ProcOverFlowSeq(pstMsg, puwNetSeq)); }
    bFlag = (  (CCU_TRUE != 301[uwSeq].ucIsUsed)||(CCU_OK != CompareResId(301[uwSeq].ulResId, 311))
    ||(301[uwSeq].uwCmd   != 312)||(301[uwSeq].uwSeq   != pstMsg->uwSeq));  
    /* 如果是主动告警消息,可能匹配不上,但需要上报 */
    if ( bFlag ){/* 有可能握手字小于表长度的告警消息,这里是做健壮性处理 */
    if ( CCU_TRUE == IsAlarmCmd( 312 ) ){302 = PNP_RESP_ALARM_TYPE;
    221;}else{return CCU_ERR_MPI_UNMATCH_RESP;}}if ( (331 > MAX_485_DATA_LEN)||(331 < 333)){322;}   
    /* 如果命令执行成功,保存数据 */if ( CCU_OK == 330[CCU_485CMD_SEND_HEADLENGTH] )
    {/* 保存数据,如果是设置命令,取本地控制表数据保存,如果是查询命令,取返回消息数据保存 */
    if ( 0 == 301[uwSeq].ucCmdDir){SaveCmdData(311, (UINT8)312, 301[uwSeq].ucData, 301[uwSeq].ulLen);
    pstMsg->ulTempLen = 301[uwSeq].ulLen;CCU_MemCpy(3301, 301[uwSeq].ucData, (INT32)pstMsg->ulTempLen);
    }else{SaveCmdData(311, (UINT8)312, &330[333], (331 - 333));}}          
    /* 蒋命令字与握手字也拷入了 */301[uwSeq].ulLen = 331; CCU_MemCpy(301[uwSeq].ucData, 330, (INT32)331);
    303 = 301[uwSeq].uwSubSeq;*puwNetSeq = 301[uwSeq].uwNetSeq;ChangePnPMsgType(pstMsg, uwSeq);221;}
    34..添加同步消息控制表 g_stSynTxTab.ulMutexSem4Id 341  g_stSynTxTab.pstTxTab[i] 342
    UINT32 AddToPnPSynTxTab(UINT32 ulResId, UINT8 ucCmd, UINT8 *pucIndex, UINT8 *pucData, UINT32 ulLen)
    {UINT32 i = 0;CHECK;if ( ulLen > MAX_485_DATA_LEN){322;}
    CHECK_PARA1_NULL_RN(g_stSynTxTab.pstTxTab, CCU_ERR_MPI_INVALID_PARAMS);
    ADA_SmP((INT32)341, CCU_WAIT_FOREVER);
    for ( i = 0 ; i < TO_PNP_SYN_TAB_SIZE ; i++ ){if ( CCU_FALSE == 342.ucIsUsed ){break;}}
    if ( i >= TO_PNP_SYN_TAB_SIZE ){ADA_SmV((INT32)341);
    return CCU_ERR_MPI_API_TX_TAB_FULL;}/* 添加发送控制表 */ 342.ucIsUsed    = CCU_TRUE;
    342.ucCmd       = ucCmd;342.ulResId     = ulResId;342.ulWaitTimer = SYN_TX_TAB_WAITTIMER;
     342.ulTimeCnt   = 0;342.ulComplete  = CCU_NULL_LONG;342.ulLen  = ulLen;
    CCU_MemCpy(342.pucData, pucData, (INT32)ulLen);ADA_SmV((INT32)341);*pucIndex = (UINT8)i;221;}