線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:735
推到 Plurk!
推到 Facebook!

動能form 和其用到指標

答題得分者是:ENIX007
kenbcb
中階會員


發表:171
回覆:129
積分:60
註冊:2003-07-15

發送簡訊給我
#1 引用回覆 回覆 發表時間:2004-05-28 12:07:37 IP:220.130.xxx.xxx 未訂閱
請問各位大大:    我可以動態開了二個以上的form, 但其有一送資料的地方,由tclientsoket送出, 但我用要送form1的東西同時帶有form的id, 但送出卻是form2的內容..    反正就是 動態form內的宣告指標(私用), 但動態開了二個,結果指標是同一個  
#pragma resource "*.dfm"
TClientForm *ClientForm;    GDT_Style *GT; // <-------------問題點
TClientSocket *NSocket;
AnsiString DName,SocketName;
int SendCount;
extern GDT_Style *GHead;
extern Pclient_Style *PHead;
extern unsigned short MonitorCount,SocketFlag[MAX_Pclient];
//---------------------------------------------------------------------------
__fastcall TClientForm::TClientForm(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TClientForm::FormClose(TObject *Sender,
      TCloseAction &Action)
{
   SocketFlag[(unsigned char)GT->PclientID] = SocketFlag[(unsigned char)GT->PclientID]-1;
   if(SocketFlag[(unsigned char)GT->PclientID] == 0) NSocket->Active = false;
   MonitorCount--;
   MainForm->HostViewClick(Sender);
   Action = caFree;
}
//---------------------------------------------------------------------------
void __fastcall TClientForm::FormCreate(TObject *Sender)
{
   //initial Value
   
   DName = MainForm->ProbeView->Selected->Caption;
   GT = (GDT_Style *)malloc(sizeof(GDT_Style));
   memset(GT,0x00,sizeof(GDT_Style));       Pclient_Style *Ptr;
   GDT_Style *GDT = GHead;
   while(GDT != NULL)
   {
      if(strncmp(GDT->Description,DName.c_str(),MAX_Alias) == 0 ||
         strncmp(GDT->ID,DName.c_str(),MAX_ID) == 0)
      {
         memmove(GT,GDT,sizeof(GDT_Style));
         Ptr = PHead;
         while(Ptr != NULL)
         {
            if(Ptr->ID == GDT->PclientID) break;
            Ptr = Ptr->Next;
         }
         break;
      }
      GDT = GDT->Next;
   }
   if(GDT == NULL) return;
   
   SocketName = "NProbeHostSocket" IntToStr((unsigned char)GT->PclientID);
   for(int i=0;iComponentCount;i  )
   {
      if(MainForm->Components[i]->Name == SocketName)
      {
         NSocket = dynamic_cast(MainForm->Components[i]);
         if(NSocket->Active == false)
         {
            NSocket->Active = true;
            DataTimer->Enabled = true;
            ShowMessage("Connect......");                char Buf[22];
            unsigned char CRC;
            Front_Pack FBuf;
            FBuf.Leading = Header;
            FBuf.Control = Command;
            FBuf.To = Server;
            FBuf.Length = 11;
            FBuf.SenderSN = 0;
            FBuf.ReceiverSN = 0;
            FBuf.Type = Request_Online;
            memmove(Buf,&FBuf,sizeof(Front_Pack));
            memmove(Buf sizeof(Front_Pack),Ptr->Password,MAX_Password);
            memmove(Buf sizeof(Front_Pack) MAX_Password,&Ptr->ID,1);
            CRC = CRCCheck(Buf,sizeof(Front_Pack) MAX_Password 1);
            Buf[sizeof(Front_Pack) MAX_Password 1] = CRC;
            Buf[sizeof(Front_Pack) MAX_Password 2] = Trailer;
            NSocket->Socket->SendBuf(Buf,22);
         }
         SocketFlag[(unsigned char)GT->PclientID] = SocketFlag[(unsigned char)GT->PclientID] 1;
         break;
      }
   }
   
   SNEdit->Text = AnsiString(GT->ID,MAX_ID/2).Trim();
   IDEdit->Text = AnsiString(GT->ID (MAX_ID/2),MAX_ID/2).Trim();
   AliasEdit->Text = AnsiString(GT->Description,MAX_Alias).Trim();
   switch(GT->Connect)
   {
      case 'C':
           Shape->Brush->Color = clLime;
           TextLabel->Caption = "-->On Line";
           break;
      case 'D':
           Shape->Brush->Color = clYellow;
           TextLabel->Caption = "-->Off Line";
           break;
      default:
           Shape->Brush->Color = clBlue;
           TextLabel->Caption = "-->inactive";
           break;
   }
   if(GT->Emergency == 'Y')
   {
      Shape->Brush->Color = clRed;
      TextLabel->Caption = "-->SOS";
   }
}
//---------------------------------------------------------------------------
 
發表人 - kenbcb 於 2004/05/28 13:43:37
ENIX007
高階會員


發表:28
回覆:274
積分:185
註冊:2003-11-27

發送簡訊給我
#2 引用回覆 回覆 發表時間:2004-05-31 09:20:26 IP:210.243.xxx.xxx 未訂閱
kenbcb您好 我想是因為GT是全域指標的關係... 當Form2 Create時,GT就指向Form2了,此時它跟Form1沒有關係... 拿它來送Form1的資料當然不行... 建議您把該指標放到TClientForm這個class裡,這樣2個Form就 各自有自己的一個指標GT,應該就可以了 程式迷人之處,在於邏輯思考,然而卻也是惱人之處~~
------
程式迷人之處,在於邏輯思考,然而卻也是惱人之處~~
系統時間:2024-11-22 22:19:00
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!