Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- En el Unit.cpp:
- #include <vcl.h>
- #include "Unit1.h"
- #include "ClasePrueba.h"
- //---------------------------------------------------------------------------
- #pragma package(smart_init)
- #pragma resource "*.dfm"
- TForm1 *Form1;
- TClase *C; //Puntero a la clase
- //---------------------------------------------------------------------------
- __fastcall TForm1::TForm1(TComponent* Owner)
- : TForm(Owner)
- {
- }
- //---------------------------------------------------------------------------
- //Creo la clase
- void __fastcall TForm1::FormCreate(TObject *Sender)
- {
- C = new TClase();
- }
- //---------------------------------------------------------------------------
- //Destruyo la clase
- void __fastcall TForm1::FormDestroy(TObject *Sender)
- {
- delete C;
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::Button1Click(TObject *Sender)
- {
- //Comprobamos que haya algo en el TEdit que debe contener el entero
- if(Edit1->Text != "")
- {
- Edit2->Text = C->Int->ToHex(Edit1->Text.ToInt());
- }else{
- Edit2->Text = "";
- }
- }
- //---------------------------------------------------------------------------
- //Filtramos para que no se pueda introducir algo diferente a numeros
- void __fastcall TForm1::Edit1KeyPress(TObject *Sender, char &Key)
- {
- if(Key < '0' || Key > '9')
- if(Key != '\b')
- Key = 0;
- }
- //---------------------------------------------------------------------------
- En el ClasePrueba.cpp:
- #include "ClasePrueba.h"
- //Constructor
- TClase::TClase()
- {
- Int = new TInt;
- Int->ToHex = IntToHex;
- }
- //Destructor
- TClase::~TClase()
- {
- delete Int;
- Int = NULL;
- }
- //Metodo de la clase
- AnsiString __fastcall TClase::IntToHex(int value)
- {
- I = value;
- return AnsiString().sprintf("0x%s",AnsiString().IntToHex(+I,8));
- }
- En el ClasePrueba.h:
- #include <vcl.h>
- #ifndef ClasePruebaH
- #define ClasePruebaH
- //---------------------------------------------------------------------------
- class TClase
- {
- private:
- double I; //Variable privada
- AnsiString __fastcall IntToHex(int value); //Metodo privado
- public:
- TClase();
- ~TClase();
- //Declaracion del tipo de funcion
- typedef AnsiString __fastcall(__closure* POINT_FUNC_RET_STRING)(int value);
- //Declaracion de la estructura que contendrĂ¡ los punteros a funciones
- typedef struct
- {
- POINT_FUNC_RET_STRING ToHex;
- }TInt;
- //Puntero a estructura que definimos
- TInt *Int;
- };
- //---------------------------------------------------------------------------
- #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement