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

【問題】在struct中使用元件的問題

答題得分者是:fffhghgjh
twcaca
一般會員


發表:1
回覆:1
積分:0
註冊:2005-02-13

發送簡訊給我
#1 引用回覆 回覆 發表時間:2005-02-14 09:32:25 IP:218.165.xxx.xxx 未訂閱
小弟寫了一個程式如下(在unit1.cpp)     //---------------------------------------------------------------------------    #include  #pragma hdrstop #include "Unit1.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TForm1 *Form1; struct node { char data; struct node *left,*right; }; struct node *mkbintree(char *treestring,struct node *root); //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- void __fastcall TForm1::Button1Click(TObject *Sender) { char chr[1000] = "abcd"; node *bintree; bintree = NULL; mkbintree(chr,bintree); } //--------------------------------------------------------------------------- struct node *mkbintree(char *treestring,struct node *root) { . . Edit1->Text = "abc"; . . . } //--------------------------------------------------------------------------- 如果我在struct node *mkbintree(char *treestring,struct node *root){} 中使用到bcb的元件如(Edit,Memo...),都會出現"[C Error] Unit1.cpp(35): E2451 Undefined symbol 'Edit1'"的訊息. 請問要如何才能在struct node *mkbintree(char *treestring,struct node *root){}中使用bcb的元件?
fffhghgjh
一般會員


發表:2
回覆:33
積分:17
註冊:2004-12-23

發送簡訊給我
#2 引用回覆 回覆 發表時間:2005-02-14 09:51:01 IP:61.222.xxx.xxx 未訂閱
struct node { char data; struct node *left,*right; }; 放在unit1.h中的class form1中 宣告
twcaca
一般會員


發表:1
回覆:1
積分:0
註冊:2005-02-13

發送簡訊給我
#3 引用回覆 回覆 發表時間:2005-02-14 11:23:58 IP:218.165.xxx.xxx 未訂閱
多謝 fffhghgjh 給個尋找的方向. 找到之前有篇類的文章 http://delphi.ktop.com.tw/topic.php?topic_id=53379 修改過後程式已經能執行了.如下. unit1.cpp //---------------------------------------------------------------------------    #include  #pragma hdrstop #include "Unit1.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TForm1 *Form1; node *mkbintree(char *treestring,struct node *root); //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- void __fastcall TForm1::Button1Click(TObject *Sender) { char chr[1000] = "abcd"; node *bintree; bintree = NULL; mkbintree(chr,bintree); } //--------------------------------------------------------------------------- node * __fastcall TForm1::mkbintree(char *treestring,struct node *root) { . Edit1->Text = "abc"; . . . } unit1.h //--------------------------------------------------------------------------- #ifndef Unit1H #define Unit1H //--------------------------------------------------------------------------- #include #include #include #include <Forms.hpp> //--------------------------------------------------------------------------- struct node { char data; struct node *left,*right; }; class TForm1 : public TForm { __published: // IDE-managed Components TButton *Button1; TEdit *Edit1; void __fastcall Button1Click(TObject *Sender); private: // User declarations public: // User declarations __fastcall TForm1(TComponent* Owner); node * __fastcall mkbintree(char *treestring,struct node *root); }; //--------------------------------------------------------------------------- extern PACKAGE TForm1 *Form1; //--------------------------------------------------------------------------- #endif 只不過有個問題,如果將struct node弄在class TForm1,似乎會有錯誤產生,要像 http://delphi.ktop.com.tw/topic.php?topic_id=53379 文章內說的,放在class TForm1之前才可以,這樣是對的嗎?
系統時間:2024-05-19 19:22:24
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!