A6 C++C++••••?

Copyright ©2009 Embarcadero Technologies, Inc. All Rights Reserved.

Demo2?

•••••••••

Copyright ©2009 Embarcadero Technologies, Inc. All Rights Reserved.

4

•••
•

(• C++Builder(C++
••)

())

Delphi…

• C++Builder• C++Builder•• C++Builder

C++Builder•

Copyright ©2009 Embarcadero Technologies, Inc. All Rights Reserved.

5

DemoTRedLabel•• TLable•(.cproj• [••]-[)]-[– C++Builder](.h, .cpp)• []-[VCL]• TRedLabel – RedLabel.h, RedLabel.cpp• Register• Color•,clRed• .bpl, .bpi, .lib
• []-[Copyright ©2009 Embarcadero Technologies, Inc. All Rights Reserved.

]
7

Demo•

UpperCase• bool –• __published:false• __property bool UpperCase = {read=FUpperCase, write=SetUpperCase};••

Copyright ©2009 Embarcadero Technologies, Inc. All Rights Reserved.

UpperCase

8

Demo

•
OnChange• TNotifyEvent• CM_TEXTCHANGED• BEGIN_MESSAGE_MAP• VCL_MESSAGE_HANDLER(• END_MESSAGE_MAP(Copyright ©2009 Embarcadero Technologies, Inc. All Rights Reserved.

ID,,))

9private
protected
public__publishedpublicC++Builder__publishedprivateprotected
public__published

Copyright ©2009 Embarcadero Technologies, Inc. All Rights Reserved.

11

VCL

TComponent

TComponent

C++Builder

TControl
TGraphicControl
TLabel TSpeedButton TShape
TWinControl

TEdit TButton TStringGrid
Copyright ©2009 Embarcadero Technologies, Inc. All Rights Reserved.

12

TObject
TPersistent
TComponent• TComponent•• TComponent•TComponent* AOwner

Button1 = new TButton(OwnerCompo);

••
()

•

Copyright ©2009 Embarcadero Technologies, Inc. All Rights Reserved.

13

TCustomControl

TObjectTControl

TPersistent
TWinControl

TGraphicControl

TComponent
TCustomControl•• TCustomControl
TWinControl
Canvas•TPanel TRadioGroup TStringGrid• OS
TCustomControl
Copyright ©2009 Embarcadero Technologies, Inc. All Rights Reserved.

14

.DFM

•
(.DFM)•• __published•(__property)
default• default•

0, NULL,

storedtrue(true)• .DFM• TComponent• virtual void __fastcall Loaded(void);•?
• TComponent

ComponentState

Copyright ©2009 Embarcadero Technologies, Inc. All Rights Reserved.

15

default•(.DFM)
.exe
•

.DFM•

default• __property int Value = { read=FValue, write=FValue, default=100 };•• default• default.DFM•• default!!

• default••

×Copyright ©2009 Embarcadero Technologies, Inc. All Rights Reserved.

16

•
•
• Classes

TNotifyEvent– typedef void __fastcall (__closure *TNotifyEvent)(System::TObject* Sender);•()•– typedef»»Sender__fastcall (__closure *T+)(+ EventTObject*);

typedef void __fastcall (__closure *TChangeCaptionEvent)(System::TObject**TChangeCaptionEvent)(System::TObject* Sender, TCaption NewCaption);...
class PACKAGE TSampleLabel : public TCustomLabel {private://TChangeCaptionEvent FOnChangeCaption;...
__published://__property__property TChangeCaptionEvent OnChangeCaption = { read=FOnChangeCaption,
read=FOnChangeCaption, write=FOnChangeCaption };...
};Copyright ©2009 Embarcadero Technologies, Inc. All Rights Reserved.

17

•
...
private:TPen* FPen;
protedted:
void __fastcall TBoxShape::SetPen(TPen* Value) {// TPen?
}public:__fastcall TBoxShape(TComponent* Owner) : TGraphicControl(Owner)
TGraphicControl(Owner) {FPen = new TPen(); //}virtual __fastcall ~TBoxShape() {delete FPen; //FPen = NULL;}__published:__property TPen* Pen = { read=FPen, write=SetPen };...
};Copyright ©2009 Embarcadero Technologies, Inc. All Rights Reserved.

( )FPen = Value;( )delete FPen;
FPen = Value;( )if( FPen != Value ) {delete FPen;
FPen = Value;}( )FPenFPen->Assign(Value);18•• VCL...
private:TWinControl* FFocusControl;
protected:
void __fastcall SetFocusControl(TWinControl* Value) {FFocusControl = Value;}
void __fastcall Notification(TComponent* Acomponent, TOperation
TOperation Operation) {TCustomLabel::Notification(Acomponent, Operation)://NULL
if( (Operation == opRemove) && (AComponent == FFocusControl) )FFocusControl = NULL;}...
__published://__property__property TWinControl* FocusControl = { read=FFocusControl, write=write= SetFocusControl };... ©2009 Embarcadero Technologies, Inc. All Rights Reserved.
Copyright

19

Q&A

Q&A

Copyright ©2009 Embarcadero Technologies, Inc. All Rights Reserved.

20