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

如何解釋Cool Bar的程式

答題得分者是:senso
energybody
一般會員


發表:44
回覆:32
積分:15
註冊:2007-04-12

發送簡訊給我
#1 引用回覆 回覆 發表時間:2010-09-27 11:13:05 IP:114.42.xxx.xxx 訂閱
小弟剛學BCB 6的程式,可是有一些看不懂,想請各位大大幫忙.

//---------------------------------------------------------------------------
#include
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "trayicon"
#pragma link "CSPIN"
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
TCoolBar *pCoolBar = new TCoolBar(this);==========>一定要加this嗎?
//TCoolBand *vCoolBand = new TCoolBand();
TList *pList;
pCoolBar->Parent = this;-------------->表示pCoolBar是This的成員?
pCoolBar->Align = alTop;
pList = new TList();
try
{
TControl *pControl;
pControl = new TToolBar(pCoolBar);=================>表示要New一個pCoolBar的一樣大的記憶體嗎?
pList->Add(pControl);
pControl = new TButton(pCoolBar);
pList->Add(pControl);
pControl = new TCheckBox(pCoolBar);
pList->Add(pControl);
pControl = new TEdit(pCoolBar);
pList->Add(pControl);
pControl = new TButton(pCoolBar);
pList->Add(pControl);
AddBands(pCoolBar, pList);
}
catch (...)
{
ShowMessage("Some objects could not be added to Coolband");
}
delete pList;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::AddBands(TCoolBar *CoolBar, TList *Objects)
{
TControl *pCurrent;
for (int i = 0; i < Objects->Count; i )
{
pCurrent = (TControl *)Objects->Items[i];
// only add windowed controls to the coolbar
if (dynamic_cast(pCurrent) != NULL)
{
// Placing the control onto the CoolBar
// causes the TCoolBar object to create a TCoolBand
// and place the control within the band.
pCurrent->Parent = CoolBar;===================>建立一個CoolBand, 但是很長,如何修改到一般的長度?
//CoolBar->Bands[0].Items->FixedSize = true;
// Get the reference of the TCoolBand just created and assign text.
int j=CoolBar->Bands->Count - 1;
CoolBar->Bands->Items[j]->Text =
pCurrent->ClassName();
}
}
CoolBar->Height = 800;
ShowMessage(IntToStr(CoolBar->Height));
}
senso
高階會員


發表:5
回覆:126
積分:226
註冊:2003-11-27

發送簡訊給我
#2 引用回覆 回覆 發表時間:2010-09-28 11:20:05 IP:61.219.xxx.xxx 訂閱
//---------------------------------------------------------------------------
#include
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "trayicon"
#pragma link "CSPIN"
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
//這邊的this指的是Form1
//而TCoolBar(TComponent *AOwner);參數指定owner,傳入this即Form1,由Form1管理此記憶體,Form1結束時會釋放此物件pCoolBar
TCoolBar *pCoolBar = new TCoolBar(this);
TList *pList;
pCoolBar->Parent = this; //Indicates the parent of the control. 將此物件顯示在哪個控制元件上
pCoolBar->Align = alTop;
pList = new TList();
try
{
TControl *pControl;
//TControl is the base class for all components that are visible at runtime.
//TControl是所有可視元件的基底類別,可以此new TButton等子類別物件裝在TControl裡
//此處pCoolBar同前段是TComponent *AOwner參數,在pCoolBar結束時會釋放掉這些owner是pCoolBar的物件
pControl = new TToolBar(pCoolBar);
pList->Add(pControl);
pControl = new TButton(pCoolBar);
pList->Add(pControl);
pControl = new TCheckBox(pCoolBar);
pList->Add(pControl);
pControl = new TEdit(pCoolBar);
pList->Add(pControl);
pControl = new TButton(pCoolBar);
pList->Add(pControl);
AddBands(pCoolBar, pList);
}
catch (...)
{
ShowMessage("Some objects could not be added to Coolband");
}
delete pList;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::AddBands(TCoolBar *CoolBar, TList *Objects)
{
TControl *pCurrent;
for (int i = 0; i < Objects->Count; i )
{
pCurrent = (TControl *)Objects->Items[i];
// only add windowed controls to the coolbar
if (dynamic_cast(pCurrent) != NULL)
{
// Placing the control onto the CoolBar
// causes the TCoolBar object to create a TCoolBand
// and place the control within the band.
pCurrent->Parent = CoolBar; // 同前段指定顯示在哪個控制元件上Placing the control onto the CoolBar
//CoolBar->Bands[0].Items->FixedSize = true;
// Get the reference of the TCoolBand just created and assign text.
int j=CoolBar->Bands->Count - 1;
CoolBar->Bands->Items[j]->Text =
pCurrent->ClassName();
}
}
CoolBar->Height = 800;
ShowMessage(IntToStr(CoolBar->Height));
}
系統時間:2017-12-17 6:26:13
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!