| Declaration | Top Previous Next | 
| New features since Delphi 7 > Generics > Declaration The following code demonstrated the conversion of a generic Delphi type to C++. 
 type TPair<TKey,TValue> = class // declares TPair type with two type parameters 
 private FKey: TKey; FValue: TValue; public function GetKey: TKey; procedure SetKey(key: TKey); function GetValue: TValue; procedure SetValue(Value: TValue); property key: TKey Read GetKey Write SetKey; property Value: TValue Read GetValue Write SetValue; end; 
 type TSIPair = TPair<String,Integer>; // declares instantiated type TSSPair = TPair<String,String>; // declares with other data types TISPair = TPair<Integer,String>; TIIPair = TPair<Integer,Integer>; TSXPair = TPair<String,TXMLNode>; 
 implementation 
 function TPair<TKey,TValue>.GetValue: TValue; begin Result := FValue; end; 
 
 -> 
 
 // declares TPair type with two type parameters template<typename TKey, typename TValue> class TPair : public System::TObject { public: typedef System::TObject inherited; private: TKey FKey; TValue FValue; public: TKey GetKey() const; void SetKey(TKey key); TValue GetValue() const; void SetValue(TValue Value); /*property key : TKey read GetKey write SetKey;*/ TKey ReadPropertykey() const { return GetKey();} void WritePropertykey(TKey key){SetKey(key);} /*property Value : TValue read GetValue write SetValue;*/ TValue ReadPropertyValue() const { return GetValue();} void WritePropertyValue(TValue Value){SetValue(Value);} TPair() {} }; typedef TPair<System::String, int> TSIPair; // declares instantiated type typedef TPair<System::String, System::String> TSSPair; // declares with other data types typedef TPair<int, System::String> TISPair; typedef TPair<int, int> TIIPair; typedef TPair<System::String, TXMLNode> TSXPair; 
 
 
 
 template<typename TKey, typename TValue> TValue TPair<TKey, TValue>::GetValue() const { TValue result; result = FValue; return result; } 
 
 
 
 
 
 
 
 
 | 
| This page belongs to the Delphi2Cpp Documentation | Delphi2Cpp home Content |