![]() |
![]() |
![]() |
![]() |
![]() |
FTP | ![]() |
![]() |
CCD | ![]() |
![]() |
Buscar | ![]() |
![]() |
Trucos | ![]() |
![]() |
Trabajo | ![]() |
![]() |
Foros | ![]() |
|
Registrarse | FAQ | Miembros | Calendario | Guía de estilo | Buscar | Temas de Hoy | Marcar Foros Como Leídos |
![]() |
|
Herramientas | Buscar en Tema | Desplegado |
|
#1
|
|||
|
|||
Referenciar TStringGrid en una clase? C++
Saludos, me surgió una gran duda. Tengo una clase matriz con dos ficheros: Matriz.h y otro Matriz.cpp, en el fichero .cpp accedo al StringGrid1 del formulario, tal como se ve a continuación:
Código:
#include "Matriz.h" //fichero de la clase matriz #include "Unit1.h" //fichero del formulario // Constructor por parámetro template<typename T> Matrix<T>::Matrix(int rows , int cols) { m_rows = rows; m_cols = cols; m_matrix = new T*[m_rows]; for (int i = 0; i < m_rows; i++) { m_matrix[i] = new T[m_cols]; } } // Llenar aleatoriamente una Matriz template<typename T> void Matrix<T>::fill_random() { for (int i = 0; i < m_rows; i++) { for (int j = 0; j < m_cols; j++) { //m_matrix[i][j] = rand() % 30; Form1->StringGrid1->Cells[i][j] = rand() % 30; //AQUÍ, DUDA. } } srand(time(NULL)); } Código:
#include "Unit1.h" #include "Matriz.cpp" #include "Matriz.h" //Llenado de matriz void Llenar_Matriz(TStringGrid *v){ v->RowCount=StrToInt(InputBox("FILA","Indique m: ","")); //crea celdas/filas v->ColCount=StrToInt(InputBox("COLUMNA","Indique n: ","")); //crea celdas/columnas int fil = v->RowCount; int col = v->ColCount; Matrix<int> Crear(fil, col); //constructor con parámetros Crear.fill_random(); //llamada a método de la clase Matriz // v->Cells[DUDA][DUDA] = Crear.fill_random(); //DUDA } void __fastcall TForm1::Button1Click(TObject *Sender) { Llenar_Matriz(StringGrid1); } |
#2
|
||||
|
||||
No me parece adecuado usar una clase genérica de esa forma.
Lo correcto sería dejar la clase como lo que es, dotarla de una forma de extraer los datos como puede ser el operador [] o una función y usar esta forma para rellenar tu StringGrid desde un método del mismo Formulario. De esta forma fill_random() sólo llenaría la matriz de forma aleatoria y sería otra función la que desde el mismo formulatio llenara tu StringGrid (otro componente, o lo que sea) con esos datos. Saludos. |
![]() |
Herramientas | Buscar en Tema |
Desplegado | |
|
|
![]() |
||||
Tema | Autor | Foro | Respuestas | Último mensaje |
referenciar y liberar componentes | g_ferrada | Varios | 4 | 19-12-2012 15:39:46 |
dejar de referenciar una dll | fedeloko | OOP | 3 | 07-09-2006 16:13:58 |
Como referenciar un IWFrame en HTML | Capo | Internet | 1 | 26-07-2006 00:17:57 |
Referenciar componente con un string | ingel | Varios | 14 | 21-06-2005 21:01:57 |
Como referenciar objetos? | Iceman | OOP | 2 | 30-11-2004 16:52:05 |
![]() |
|