TEdit
27.07.1999
  • Wyrównanie tekstu do prawej strony w kontrolce Edit.

      Wymaga to utworzenia nowego komponentu, który dziedziczy z TEdit i zmiany metody CreateParams. Jeżeli tworzysz pod Windows 95/NT4 będziesz musiał dodać flagę ES_MULTILINE. Poniżej kod źródłowy komponentu TREdit.

//----------------------------------------------
/ REditCode.h =================================
//----------------------------------------------
#ifndef REditCodeH 
#define REditCodeH 
//----------------------------------------------
#include <vcl\SysUtils.hpp>
#include <vcl\Controls.hpp>
#include <vcl\Classes.hpp>
#include <vcl\Forms.hpp>
#include <vcl\StdCtrls.hpp> 
//----------------------------------------------
#if (__BORLANDC__ < 0x0530) 
//-----------------------------------------------
// BCB 1.0 
//-----------------------------------------------
  #define PACKAGE 
  #define DYNAMIC 
#endif 
//------------------------------------------------

class PACKAGE TREdit : public TEdit 
{ 
private: 
protected: 
public: 
   __fastcall TREdit(TComponent* Owner); 
   virtual void __fastcall CreateParams(TCreateParams &Params); 
__published: 
}; 
//-------------------------------------------------
#endif 


//--------------------------------------------------
// REditCode.cpp ===================================
//--------------------------------------------------
#include <vcl\vcl.h> 
#pragma hdrstop 
#include "REditCode.h" 
//--------------------------------------------------
#if (__BORLANDC__ < 0x0530) 
//--------------------------------------------------
// BCB 1.0 
//--------------------------------------------------
static inline TREdit *ValidCtrCheck() 
{ 
   return new TREdit(NULL); 
} 
//-------------------------------------------------
#else 
//-------------------------------------------------
// BCB 3.0/4.0 
//-------------------------------------------------
#pragma package(smart_init) 
//-------------------------------------------------
// ValidCtrCheck is used to assure that the components
   created do not have 
// any pure virtual functions. 
// 
static inline void ValidCtrCheck(TREdit *) 
{ 
   new TREdit(NULL); 
} 
//--------------------------------------------------
#endif 

//--------------------------------------------------
__fastcall TREdit::TREdit(TComponent* Owner) 
: TEdit(Owner) 
{ 
} 

//--------------------------------------------------
void __fastcall TREdit::CreateParams(TCreateParams &Params) 
{ 
    TEdit::CreateParams(Params); 
    Params.Style = Params.Style | ES_RIGHT;// ES_MULTILINE; 
} 

//--------------------------------------------------
namespace Reditcode 
{ 
   void __fastcall PACKAGE Register() 
    { 
        TComponentClass classes[1] = {__classid(TREdit)}; 
        RegisterComponents("Samples", classes, 0); 
    } 
}