Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Lazarus, FreePascal, Kylix, etc. (https://www.clubdelphi.com/foros/forumdisplay.php?f=14)
-   -   Ayuda con un StringGrid (https://www.clubdelphi.com/foros/showthread.php?t=59400)

maky 25-08-2008 21:59:43

Ayuda con un StringGrid
 
Empezado por maky
ola pus necesto auyada con un StringGird;
que se muestre el arreglo en un stringGrid y que vaya recorriendo los renglones para que al final de arreglo sume todas las cantidades ingresadas y saque el promedio por ejemplo algo asi

1|5
2|5
3|5


y promedio mostramos en un label

espero me puedad ayuda gracias


--se una en edit
-- un pboton porel cual seingresan los datos a un StringGrid
y otro boton realizar la operacion y el label paramostrar el resulatdo
espero e puedan ayudar ok

Delphius 25-08-2008 22:15:15

Hola maky,
Espero que no te haya molestado que te haya pedido que al temas lo expongas en el foro en ves de tratarlo en forma privada.

Noto que a tu duda la expones en el sub-foro de Kylix, Lazarus, etc.
Yo no uso ninguno de estos entornos. Yo uso Delphi, si es Lazarus lo que usas no sabría decir hasta que punto el código sea tan similar desde Delphi.

Quería preguntarte, antes de arriesgarme a poner código, si el promedio a obtener es ¿renglón por renglón? Es decir esto:

renglón 1: dato1 | dato2 | datoN | Promedio
renglón M: dato1 | dato2 | datoN | Promedio

¿O se trata de obtener el promedio de las los renglones, columna por columna?

fila 1 | fila 2|
Dato1| Dato1 |
Dato2 | Dato2 |
...
Promedio | Promedio |

Saludos,

maky 26-08-2008 16:55:52

otra vez molestandote jaja
 
talvez sea muy sencillo pero apenasestoy aperendiendo a menejar delphi
mira esto es lo que llevo hasta ahora de codigo pero presiento que falta algo a ver si puedes ayudarme ok.

type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
SGNums: TStringGrid;
Button2: TButton;
Label1: TLabel;
Label2: TLabel;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
nums: array of integer;
Tam:integer;
// row:integer;
{ Private declarations }
public
{ Public declarations }
rcount:integer;

end;
var
Form1: TForm1;

implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var valor:integer;
//begin
//if (row<Tam) then

i, j:Integer;
Str:String;
begin
valor:= StrToInt (Edit1.Text);
setLength (nums,20);
SGNums.Cells[1,1]:=Edit1.Text;
SGNums.RowCount:=SGNums.RowCount+1;
for j := 0 to (SGNums.Rows[i].Count - 1) do begin
//SGNums.ColsCount:=SGNums.ColsCount+1
//SGNums.ColCount;
//SGNums.Row:= SGNums.Row+1;
end;
end;
//edit1.setfocus;
procedure TForm1.FormCreate(Sender: TObject);
begin
SGNums.Cells[0,0]:='Posicion';
SGNums.Cells[1,0]:='Valor';


end;
end.

maeyanes 26-08-2008 17:09:29

Hola...

Veo que eres nuevo en estos foros, así que primero te doy la bienvenida y luego te invito a que leas la Guía de Estilo de estos foros (enlace arriba del banner :))

También te pido que cuando publiques código fuente en estos foros, uses las etiquetas [ DELPHI ] [ /DELPHI ] (sin los espacios en blanco). De esta forma tu código se verá más presentable:

Código Delphi [-]
type
  TForm1 = class(TForm)
    Button1: TButton;
    Edit1: TEdit;
    SGNums: TStringGrid;
    Button2: TButton;
    Label1: TLabel;
    Label2: TLabel;
    procedure Button1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    nums: array of integer;
    Tam:integer;
    // row:integer;
    { Private declarations }
  public
    { Public declarations }
    rcount:integer;
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var valor:integer;
  //begin
  //if (row  i, j:Integer;
  Str:String;

begin
  valor:= StrToInt (Edit1.Text);
  setLength (nums,20);
  SGNums.Cells[1,1]:=Edit1.Text;
  SGNums.RowCount:=SGNums.RowCount+1;
  for j := 0 to (SGNums.Rows[i].Count - 1) do begin
    //SGNums.ColsCount:=SGNums.ColsCount+1
    //SGNums.ColCount;
    //SGNums.Row:= SGNums.Row+1;
  end;
end;

//edit1.setfocus;
procedure TForm1.FormCreate(Sender: TObject);
begin
  SGNums.Cells[0,0]:='Posicion';
  SGNums.Cells[1,0]:='Valor';

end;

end.

¿Ves la diferencia?


Saludos...

maky 26-08-2008 17:22:07

Respuesta
 
Ok Gracias

Caro 27-08-2008 17:28:29

Hola Maky, porque quieres guardar los datos en un arreglo, no sería mejor que le permitieras llenar directamente dentro de las celdas y que se vaya sumando y mostrando en tu Label, paar permitir editar la celda del StringGrid debes colocar a True la propiedad Options->goEditing, suponiendo que quieres sumar la columna Valor, puedes hacerlo mas o menos de esta forma

Código Delphi [-]
//Nuestro procedimiento que nos suma todas las celdas de la columna 1 (Valor)
procedure TForm1.SumarCeldas;
var
 Fila, Total : Integer;
 Valor : String;
begin
 if SGNums.Col=1 then //Si estamos en nuestra columna 1
  begin
   Total := 0;
   for Fila:=0 to SGNums.RowCount-1 do
    begin
     Valor := SGNums.Cells[1,Fila];
     if Trim(Valor)='' then
      Valor := '0';
     Total := Total + StrToInt(Valor);
    end;
   Label1.Caption := IntToStr(Total);
  end;
end;
 
//Y luego llamamos en estos dos eventos del StringGrid
procedure TForm1.SGNumsSelectCell(Sender: TObject; ACol,
  ARow: Integer; var CanSelect: Boolean);
begin
 SumarCeldas;
end;
 
procedure TForm1.SGNumsExit(Sender: TObject);
begin
 SumarCeldas;
end;

Trata de explicar lo mas que puedas tu problema, para que puedas recibir mas ayuda de todos.

Saluditos

maky 27-08-2008 18:45:59

ayuda con el SG
 
Muchas gracias fue de gran ayuda tu respuesta ok :)


La franja horaria es GMT +2. Ahora son las 18:38:32.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi