Club Delphi  
    FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Principal > Varios
Registrarse FAQ Miembros Calendario Guía de estilo Temas de Hoy

Grupo de Teaming del ClubDelphi

 
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 19-05-2006
azaghal azaghal is offline
Registrado
 
Registrado: may 2006
Posts: 1
Poder: 0
azaghal Va por buen camino
Problema con una TStringGrid

Bueno, realmente no se q pase, lo he checado mil veces y no se q anda mal, alguien me puede ayudar. Les dejo todo el codigo y tambien les dejo todos los botones q tengo. Espero alguien me ayude. Gracias.

El Programa simula el trafico de autos.

Código:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Grids, StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    StringGrid1: TStringGrid;
    Memo1: TMemo;
    Memo2: TMemo;
    Memo3: TMemo;
    Edit1: TEdit;
    StringGrid2: TStringGrid;
    Button2: TButton;
    Button3: TButton;
    Button4: TButton;
    Label1: TLabel;
    procedure Button1Click(Sender: TObject);
    procedure StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
      Rect: TRect; State: TGridDrawState);
    procedure StringGrid2DrawCell(Sender: TObject; ACol, ARow: Integer;
      Rect: TRect; State: TGridDrawState);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
var
  Columnas, veces, Renglones : Integer;
begin
  Hint := 'Da valores iniciales a la primer cadena';
  Randomize;
  for Renglones := 0 to StringGrid1.RowCount - 1 do
  for Columnas := 0 to StringGrid1.ColCount - 1 do
      StringGrid1.Cells[Columnas,Renglones] := IntToStr(0);
  for Columnas := 1 to StringGrid1.ColCount - 1 do
    Begin
      veces := Random(9) + 1;
      If (veces = 1) and (StrToInt(StringGrid1.Cells[Columnas-1,0]) = 0)then
        StringGrid1.Cells[Columnas,0] := IntToStr(Random(5) + 1);
    end;

end;

procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
  Rect: TRect; State: TGridDrawState);
Var
Velocidad : string;
Renglon : integer;
begin
  with StringGrid1 do
  begin
    for renglon := 0 to RowCount - 1 do
    begin
      Velocidad := Cells[ACol,ARow];
      if (Arow=Renglon) and (Velocidad='0') then
      begin
        Canvas.Brush.Color:=ClMaroon;
        Canvas.FillRect(rect);
      end;
      if (Arow=Renglon) and (Velocidad='1') then
      begin
        Canvas.Brush.Color:=Clred;
        Canvas.FillRect(rect);
      end;
      if (Arow=Renglon) and (Velocidad='2') then
      begin
        Canvas.Brush.Color:=Clblue;
        Canvas.FillRect(rect);
      end;
      if (Arow=Renglon) and (Velocidad='3') then
      begin
        Canvas.Brush.Color:=Clgreen;
        Canvas.FillRect(rect);
      end;
      if (Arow=Renglon) and (Velocidad='4') then
      begin
        Canvas.Brush.Color:=Clyellow;
        Canvas.FillRect(rect);
      end;
      if (Arow=Renglon) and (Velocidad='5') then
      begin
        Canvas.Brush.Color:=Clgray;
        Canvas.FillRect(rect);
      end;
    end;
  end;
end;


procedure TForm1.StringGrid2DrawCell(Sender: TObject; ACol, ARow: Integer;
  Rect: TRect; State: TGridDrawState);
Var
Velocidad : string;
begin
  with StringGrid2 do
  begin
      Velocidad := Cells[ACol,ARow];
      if (ACol=1) and (Velocidad='1') then
      begin
        Canvas.Brush.Color:=Clred;
        Canvas.FillRect(rect);
      end;
      if (ACol=1) and (Velocidad='2') then
      begin
        Canvas.Brush.Color:=Clblue;
        Canvas.FillRect(rect);
      end;
      if (ACol=1) and (Velocidad='3') then
      begin
        Canvas.Brush.Color:=Clgreen;
        Canvas.FillRect(rect);
      end;
      if (ACol=1) and (Velocidad='4') then
      begin
        Canvas.Brush.Color:=Clyellow;
        Canvas.FillRect(rect);
      end;
      if (ACol=1) and (Velocidad='5') then
      begin
        Canvas.Brush.Color:=Clgray;
        Canvas.FillRect(rect);
      end;
    end;
  end;

procedure TForm1.Button2Click(Sender: TObject);
Var
Velocidad, Renglon : Integer;
begin
  Velocidad := 0;
  for Renglon := 0 to StringGrid2.RowCount - 1 do
    Begin
      Velocidad := Velocidad + 1;
      StringGrid2.Cells[0,Renglon]:= IntToStr(Velocidad);
      StringGrid2.Cells[1,Renglon]:= IntToStr(Velocidad);
    end;
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
  Close;
end;

procedure TForm1.Button4Click(Sender: TObject);

VAR

  Columnas2, Espacio, i, automoviles : Integer;
  VelocidadV : ARRAY[0..100] OF Integer;
  Automoviles2, J, Probabilidad, VelMax : Integer;
  Columnas, NewVel, Spacio, Renglones : Integer;

BEGIN

Randomize;
FOR Renglones := 0 TO StringGrid1.RowCount - 1 DO
  BEGIN
  FOR Columnas2 := 0 TO StringGrid1.ColCount - 1 DO
    BEGIN
    IF StringGrid1.Cells[Columnas2,Renglones] = '1' THEN
      BEGIN
      VelocidadV[Columnas2] := StrToInt(StringGrid1.Cells[Columnas2,Renglones]);
      Memo2.Lines.Add(IntToStr(Columnas2));
      END
    ELSE IF StringGrid1.Cells[Columnas2,Renglones] = '2' THEN
      BEGIN
      VelocidadV[Columnas2] := StrToInt(StringGrid1.Cells[Columnas2,Renglones]);
      Memo2.Lines.Add(IntToStr(Columnas2));
      END
    ELSE IF StringGrid1.Cells[Columnas2,Renglones] = '3' THEN
      BEGIN
      VelocidadV[Columnas2] := StrToInt(StringGrid1.Cells[Columnas2,Renglones]);
      Memo2.Lines.Add(IntToStr(Columnas2));
      END
    ELSE IF StringGrid1.Cells[Columnas2,Renglones] = '4' THEN
      BEGIN
      VelocidadV[Columnas2] := StrToInt(StringGrid1.Cells[Columnas2,Renglones]);
      Memo2.Lines.Add(IntToStr(Columnas2));
      END
    ELSE IF StringGrid1.Cells[Columnas2,Renglones] = '5' THEN
      BEGIN
      VelocidadV[Columnas2] := StrToInt(StringGrid1.Cells[Columnas2,Renglones]);
      Memo2.Lines.Add(IntToStr(Columnas2));
      END
    ELSE IF StringGrid1.Cells[Columnas2,Renglones] = '0' THEN
      Espacio := Espacio + 1;
    IF StringGrid1.Cells[Columnas2,Renglones] <> '0' THEN
      BEGIN
      Memo3.Lines.Add(StringGrid1.Cells[Columnas2,Renglones]);
      Automoviles := Automoviles + 1;
      END;
    Edit1.Text := IntToStr( automoviles );
    END;
  FOR i:= 0 TO StringGrid1.Colcount - 1 DO
    Memo1.Lines.Add(IntToStr(VelocidadV[i]));
  VelMax := 5 ;
  Automoviles2 := StrToInt(Edit1.Text) - 1;
  FOR J := 0 TO Automoviles2 DO
    BEGIN
      IF J = Automoviles2 THEN
        BEGIN
        NewVel := StrToInt(Memo3.Lines[j]);
        Spacio := 79 - StrToInt(Memo2.Lines[J]);
        IF Spacio > VelMax THEN
          Spacio := VelMax;
        IF Spacio <= NewVel THEN
          NewVel := Spacio;
        Probabilidad := Random(5) + 1;
        IF (Probabilidad = 1) AND (NewVel > 1) THEN
          BEGIN
          NewVel := NewVel - 1;
          ShowMessage('La velocidad ha sido disminuida en 1');
          END;
        Columnas := StrToInt(Memo2.Lines[J]) + NewVel;
        IF Columnas < 79 THEN     //Aqui
          StringGrid1.Cells[Columnas,Renglones + 1] := IntToStr(NewVel)
        ELSE
          BEGIN
          Columnas := NewVel;
          StringGrid1.Cells[Columnas,Renglones + 1] := IntToStr(NewVel);
          END;        //Termina
        END
      ELSE
        BEGIN
        NewVel := StrToInt(Memo3.Lines[j]);
        Spacio := StrToInt(Memo2.Lines[j+1]) - StrToInt(Memo2.Lines[J]) - 1;
        IF Spacio > 5 THEN
          Spacio := 5;
        IF Spacio <= NewVel THEN
          NewVel := Spacio;
        Probabilidad := Random(5) + 1;
        IF (Probabilidad = 1) AND (NewVel > 1) THEN
          BEGIN
          NewVel := NewVel - 1;
          ShowMessage('La velocidad ha sido disminuida en 1');
          END;
        Columnas := StrToInt(Memo2.Lines[J]) + NewVel;
        IF Columnas < 79 THEN     //Aqui
          StringGrid1.Cells[Columnas,Renglones + 1] := IntToStr(NewVel)
        ELSE
          BEGIN
          Columnas := NewVel;
          StringGrid1.Cells[Columnas,Renglones + 1] := IntToStr(NewVel);
          END;        //Termina
        END;
  END;
  Memo1.Clear;
  Memo2.Clear;
  Memo3.Clear;
  END;
END;
END.

Responder Con Cita
 



Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro

Temas Similares
Tema Autor Foro Respuestas Último mensaje
Duda sobre un TStringGrid Drahcir Varios 3 23-01-2006 20:58:05
TStringGrid jorge_mosquera Varios 1 10-02-2005 16:08:45
Botón Derecho y TStringGrid Wulvay Varios 5 22-09-2004 00:53:54
Número de columnas de un TstringGrid Yenifer Varios 1 13-08-2004 00:39:50
colorear las celdas de un TstringGrid mangel OOP 2 16-12-2003 17:22:47


La franja horaria es GMT +2. Ahora son las 16:01:50.


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