FTP | CCD | Buscar | Trucos | Trabajo | Foros |
|
Registrarse | FAQ | Miembros | Calendario | Guía de estilo | Temas de Hoy |
|
Herramientas | Buscar en Tema | Desplegado |
|
#1
|
||||
|
||||
Hola eennzzoo.
Yo también había pensado en una opción similar a la publicada por dec. .h: Código:
#ifndef Unit2H #define Unit2H #include <Classes.hpp> #include <Controls.hpp> #include <StdCtrls.hpp> class Cliente { private: String FNombre; String FApellido; String FDni; String FFileName; TStrings *FTS; public: Cliente(); __property String Nombre = { read = FNombre, write = FNombre }; __property String Apellido = { read = FApellido, write = FApellido }; __property String Dni = { read = FDni, write = FDni }; __property String FileName = { read = FFileName, write = FFileName }; bool Open(); bool GetData(const String Dni); bool Delete(const String Dni); bool Save(); ~Cliente(); }; #endif Código:
#pragma hdrstop #include "Unit2.h" #pragma package(smart_init) Cliente::Cliente() { FTS = new TStringList; } bool Cliente::Open() { FTS->LoadFromFile(FFileName); return FileExists(FFileName); } bool Cliente::GetData(const String Dni) { int p = FTS->IndexOf(Dni); if (p != -1) { FNombre = FTS->Strings[p-2]; FApellido = FTS->Strings[p-1]; FDni = FTS->Strings[p]; return true; } else { MessageBox(0,"Cliente no encontrado", "", MB_ICONERROR); return false; } } bool Cliente::Delete(const String Dni) { int p = FTS->IndexOf(Dni); bool r = false; if (p == -1) MessageBox(0,"Cliente no encontrado", "", MB_ICONERROR); else if (MessageBox(0, "¿ Borra el cliente ?","",MB_YESNO+MB_ICONQUESTION)==IDYES) { FTS->Delete(p); r = true; } return r; } bool Cliente::Save() { if (FNombre.IsEmpty() || FApellido.IsEmpty() || FDni.IsEmpty()) { MessageBox(0,"Faltan uno o mas datos requeridos", "", MB_ICONERROR); return false; } else if (FTS->IndexOf(FDni)!= -1) { MessageBox(0,"Cliente existente", "", MB_ICONERROR); return false; } else { FTS->Add(FNombre); FTS->Add(FApellido); FTS->Add(FDni); FTS->SaveToFile(FFileName); return true; } }; Cliente::~Cliente() { delete FTS; } Código:
... #include "Unit2.h" ... Cliente *cl; void __fastcall TForm1::FormCreate(TObject *Sender) { cl = new Cliente(); cl->FileName = "cliente.txt"; /* ruta+nombre de archivo */ cl->Open(); } void __fastcall TForm1::btnShowClick(TObject *Sender) { if (cl->GetData(Edit1->Text)) { edNom->Text = cl->Nombre; edApe->Text = cl->Apellido; edDni->Text = cl->Dni; } } void __fastcall TForm1::btnDeleteClick(TObject *Sender) { if (cl->Delete(Edit1->Text)) { edNom->Clear(); edApe->Clear(); edDni->Clear(); } } void __fastcall TForm1::btnSaveClick(TObject *Sender) { cl->Save(); } ... Saludos
__________________
Daniel Didriksen Guía de estilo - Uso de las etiquetas - La otra guía de estilo .... |
#2
|
||||
|
||||
Cita:
__________________
▶ https://www.facebook.com/riverplateoficial ◀ |
#3
|
||||
|
||||
Hola,
Conste que mi clase de más arriba contiene un error: no destruyo la instancia de "FContenidoBaseDatos". No me he dado cuenta antes. |
#4
|
||||
|
||||
ecfisa ¿Que es eso de __property? Suena mas a un componente.
|
#5
|
||||
|
||||
Hola aguml.
Básicamente una propiedad, es una extensión creada para C++ Builder que permite unificar métodos de acceso y modificación a miembros de una clase. Su uso no es privativo de los componentes. Cabe aclarar que C++ estandar no incluye el concepto de propiedad y que C++ Builder recibe de la VCL, si tratásemos con ANSI C++ tendríamos que escribir: Código:
class MiClass { private: int FValue; public: void SetValue(int Value) { FValue = Value; } int GetValue() { return FValue; } };
__________________
Daniel Didriksen Guía de estilo - Uso de las etiquetas - La otra guía de estilo .... |
|
|
Temas Similares | ||||
Tema | Autor | Foro | Respuestas | Último mensaje |
error de missing separator con el siguiente codigo | feliz-58 | C++ Builder | 7 | 28-03-2013 14:06:05 |
Como implementar este codigo en delphi 7 | freddiaz07 | Internet | 4 | 16-09-2011 22:34:39 |
Me he atascado en el siguiente código | David | PHP | 3 | 26-02-2007 00:15:52 |
Estoy atascado en el siguiente código | David | OOP | 4 | 01-10-2006 10:45:45 |
Implementar el constructor de una clase | Alcolea | OOP | 2 | 14-06-2006 06:39:05 |
|