BCB類別 |
尚未結案
|
ji3g4go61125
一般會員 發表:1 回覆:0 積分:0 註冊:2010-06-12 發送簡訊給我 |
我現在自訂一個Image要讓它能夠利用左右鍵移動
可是現在出現問題[C Error] Unit1.cpp(70): E2451 Undefined symbol 'La' 問過朋友也找不出原因 請問是哪裡出問題 要如何改寫 [code cpp] //--------------------------------------------------------------------------- #include #pragma hdrstop #include "Unit1.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TForm1 *Form1; class Launcher { private: TImage *La; public: Launcher(); ~Launcher(); int GetLeft(),GetWidth(); }; //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- Launcher::Launcher() { La=new TImage(Form1); La->Parent=Form1; La->Picture->LoadFromFile("2.bmp"); La->Width=La->Picture->Width; La->Height=La->Picture->Height; La->Left=Form1->ClientWidth/2; La->Top=Form1->ClientHeight-La->Height; } Launcher::~Launcher(){ La->Visible=false; delete La; } int Launcher::GetLeft() { return La->Left; } int Launcher::GetWidth() { return La->Width; } void __fastcall TForm1::FormCreate(TObject *Sender) { new Launcher(); Panel1->Height=Form1->ClientHeight; Panel1->Top=0; Panel1->Left=Form1->ClientWidth-Panel1->Width; } //--------------------------------------------------------------------------- void __fastcall TForm1::FormKeyDown(TObject *Sender, WORD &Key, TShiftState Shift) { if( Key == VK_RIGHT ) // Right arrow { La->GetLeft() = La->GetLeft() 20; // if( Image1->Left Image1->Width >= Form1->ClientWidth) // Image1->Left = Form1->ClientWidth-Image1->Width 0; if( La->GetLeft() La->GetWidth() >= Form1->ClientWidth-Panel1->Width) La->GetLeft() = Form1->ClientWidth-Panel1->Width-La->GetWidth(); } else if( Key == VK_LEFT ) // Left arrow key { La->GetLeft() = La->GetLeft() - 20; if( La->GetLeft() <= 0 ) La->GetLeft()= 0; } } //--------------------------------------------------------------------------- [/code] 編輯記錄
ji3g4go61125 重新編輯於 2010-06-12 02:11:21, 註解 無‧
|
kkk730819
一般會員 發表:4 回覆:14 積分:8 註冊:2010-05-25 發送簡訊給我 |
你用副程式這樣好像有點多此一舉
而且語法有點怪 有可能是我程度不夠請見量 ex: if( Key ==39 ) // Right arrow Image1->Left =20; //Image1是我的圖片 這樣應該簡化很多 ===================引 用 ji3g4go61125 文 章=================== 我現在自訂一個Image要讓它能夠利用左右鍵移動 可是現在出現問題[C Error] Unit1.cpp(70): E2451 Undefined symbol 'La' 問過朋友也找不出原因 請問是哪裡出問題 要如何改寫 [code cpp] //--------------------------------------------------------------------------- #include #pragma hdrstop #include "Unit1.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TForm1 *Form1; class Launcher { private: TImage *La; public: Launcher(); ~Launcher(); int GetLeft(),GetWidth(); }; //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- Launcher::Launcher() { La=new TImage(Form1); La->Parent=Form1; La->Picture->LoadFromFile("2.bmp"); La->Width=La->Picture->Width; La->Height=La->Picture->Height; La->Left=Form1->ClientWidth/2; La->Top=Form1->ClientHeight-La->Height; } Launcher::~Launcher(){ La->Visible=false; delete La; } int Launcher::GetLeft() { return La->Left; } int Launcher::GetWidth() { return La->Width; } void __fastcall TForm1::FormCreate(TObject *Sender) { new Launcher(); Panel1->Height=Form1->ClientHeight; Panel1->Top=0; Panel1->Left=Form1->ClientWidth-Panel1->Width; } //--------------------------------------------------------------------------- void __fastcall TForm1::FormKeyDown(TObject *Sender, WORD &Key, TShiftState Shift) { if( Key == VK_RIGHT ) // Right arrow { La->GetLeft() = La->GetLeft() 20; // if( Image1->Left Image1->Width >= Form1->ClientWidth) // Image1->Left = Form1->ClientWidth-Image1->Width 0; if( La->GetLeft() La->GetWidth() >= Form1->ClientWidth-Panel1->Width) La->GetLeft() = Form1->ClientWidth-Panel1->Width-La->GetWidth(); } else if( Key == VK_LEFT ) // Left arrow key { La->GetLeft() = La->GetLeft() - 20; if( La->GetLeft() <= 0 ) La->GetLeft()= 0; } } //--------------------------------------------------------------------------- [/code]
------
有問題大家多討論 大家共同一起進步 |
m90102
一般會員 發表:0 回覆:1 積分:0 註冊:2010-06-12 發送簡訊給我 |
|
s92405054
高階會員 發表:7 回覆:49 積分:101 註冊:2009-04-07 發送簡訊給我 |
可是現在出現問題[C Error] Unit1.cpp(70): E2451 Undefined symbol 'La'
是不是因為private:(私有型態) TImage *La; 就無法給TForm1用阿 程度不夠請見諒....BCB初學者 ===================引 用 ji3g4go61125 文 章=================== 我現在自訂一個Image要讓它能夠利用左右鍵移動 可是現在出現問題[C Error] Unit1.cpp(70): E2451 Undefined symbol 'La' 問過朋友也找不出原因 請問是哪裡出問題 要如何改寫 [code cpp] //--------------------------------------------------------------------------- #include #pragma hdrstop #include "Unit1.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TForm1 *Form1; class Launcher { private: TImage *La; public: Launcher(); ~Launcher(); int GetLeft(),GetWidth(); }; //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- Launcher::Launcher() { La=new TImage(Form1); La->Parent=Form1; La->Picture->LoadFromFile("2.bmp"); La->Width=La->Picture->Width; La->Height=La->Picture->Height; La->Left=Form1->ClientWidth/2; La->Top=Form1->ClientHeight-La->Height; } Launcher::~Launcher(){ La->Visible=false; delete La; } int Launcher::GetLeft() { return La->Left; } int Launcher::GetWidth() { return La->Width; } void __fastcall TForm1::FormCreate(TObject *Sender) { new Launcher(); Panel1->Height=Form1->ClientHeight; Panel1->Top=0; Panel1->Left=Form1->ClientWidth-Panel1->Width; } //--------------------------------------------------------------------------- void __fastcall TForm1::FormKeyDown(TObject *Sender, WORD &Key, TShiftState Shift) { if( Key == VK_RIGHT ) // Right arrow { La->GetLeft() = La->GetLeft() 20; // if( Image1->Left Image1->Width >= Form1->ClientWidth) // Image1->Left = Form1->ClientWidth-Image1->Width 0; if( La->GetLeft() La->GetWidth() >= Form1->ClientWidth-Panel1->Width) La->GetLeft() = Form1->ClientWidth-Panel1->Width-La->GetWidth(); } else if( Key == VK_LEFT ) // Left arrow key { La->GetLeft() = La->GetLeft() - 20; if( La->GetLeft() <= 0 ) La->GetLeft()= 0; } } //--------------------------------------------------------------------------- [/code] |
senso
高階會員 發表:5 回覆:126 積分:226 註冊:2003-11-27 發送簡訊給我 |
1.你沒宣告要給誰用
Launcher *myobj; //在全域宣告 myobj = new Launcher(); //在FormCreate delete myobj; //用完就要delete,在FormClose 2.Launcher的La是private,其他類別(如Form)不能直接叫用它 你寫的GetLeft()和GetWidth()這兩個function不能那樣用,這只能取值,不能把值設進去 int tmp_left = myobj->GetLeft(); int tmp_width = myobj->GetWidth(); 要麻用property的方式寫, 不然就把TImage *La;改public,然後直接用myobj->La->Left=20; 3.屬性property應該這樣寫 protected: int getLaLeft() {return La->Left;}; void setLaLeft(int newLeft) {La->Left=newLeft;}; int getLaWidth() {return La->Width;}; void setLaWidth(int newWidth) {La->Width=newWidth;}; public: __property int LaLeft ={write=setLaLeft ,read=getLaLeft }; __property int LaWidth={write=setLaWidth,read=getLaWidth}; 然後這樣用 void __fastcall TForm1::FormKeyDown(TObject *Sender, WORD &Key, TShiftState Shift) { if( Key == VK_RIGHT ) // Right arrow { myobj->LaLeft = 20; } } |
istillloving
高階會員 發表:33 回覆:182 積分:183 註冊:2008-10-09 發送簡訊給我 |
you must use Launcher point new an Launcher before form1 member functinn use La
you can try Launcher *text = new Launcher; but La is private for Launcher , so throuh text then form1 member functinn can be use
------
恩...
編輯記錄
istillloving 重新編輯於 2010-07-05 11:44:53, 註解 無‧
istillloving 重新編輯於 2010-07-05 11:47:17, 註解 無‧ istillloving 重新編輯於 2010-07-05 11:47:45, 註解 無‧ istillloving 重新編輯於 2010-07-05 11:58:44, 註解 無‧ |
Ktop_Robot
站務副站長 發表:0 回覆:3511 積分:0 註冊:2007-04-17 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |