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

BCB類別

尚未結案
ji3g4go61125
一般會員


發表:1
回覆:0
積分:0
註冊:2010-06-12

發送簡訊給我
#1 引用回覆 回覆 發表時間:2010-06-12 02:09:32 IP:125.224.xxx.xxx 訂閱
我現在自訂一個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

發送簡訊給我
#2 引用回覆 回覆 發表時間:2010-06-14 13:51:34 IP:114.24.xxx.xxx 訂閱
你用副程式這樣好像有點多此一舉
而且語法有點怪 有可能是我程度不夠請見量
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]

------
有問題大家多討論
大家共同一起進步
編輯記錄
kkk730819 重新編輯於 2010-06-14 13:53:09, 註解 無‧
kkk730819 重新編輯於 2010-06-14 14:06:52, 註解 無‧
m90102
一般會員


發表:0
回覆:1
積分:0
註冊:2010-06-12

發送簡訊給我
#3 引用回覆 回覆 發表時間:2010-06-14 15:19:26 IP:203.64.xxx.xxx 訂閱
這是作業要求使用類別
所以才這樣用
不過這支程式還沒完成
只是想先看它會不會動
s92405054
高階會員


發表:7
回覆:49
積分:101
註冊:2009-04-07

發送簡訊給我
#4 引用回覆 回覆 發表時間:2010-06-14 16:35:45 IP:60.248.xxx.xxx 訂閱
可是現在出現問題[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

發送簡訊給我
#5 引用回覆 回覆 發表時間:2010-06-15 09:50:37 IP:61.219.xxx.xxx 訂閱
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

發送簡訊給我
#6 引用回覆 回覆 發表時間:2010-07-05 11:42:15 IP:140.127.xxx.xxx 訂閱
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

發送簡訊給我
#7 引用回覆 回覆 發表時間:2010-09-13 12:35:50 IP:000.000.xxx.xxx 未訂閱
提問者您好:


以上回應是否已得到滿意的答覆?


若已得到滿意的答覆,請在一週內結案,否則請在一週內回覆還有什麼未盡事宜,不然,
將由版主(尚無版主之區域將由副站長或站長)自由心證,選擇較合適之解答予以結案處理,
被選上之答題者同樣會有加分獎勵同時發問者將受到扣 1 分的處分。不便之處,請見諒。


有問有答有結案,才能有良性的互動,良好的討論環境需要大家共同維護,感謝您的配合。

------
我是機器人,我不接受簡訊.
系統時間:2024-04-20 2:19:04
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!