Ver Mensaje Individual
  #1  
Antiguo 20-08-2021
Aszael Aszael is offline
Registrado
 
Registrado: nov 2017
Posts: 7
Reputación: 0
Aszael Va por buen camino
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));
}
Y hago la llamada en el Form1, Unit1.cpp de la siguiente forma:
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);
}
Mi duda es si está ¿es la manera correcta de acceder y llamar al objeto TStringGrid? Y una ayudita si no lo es. Gracias de antemano.
Responder Con Cita