Ir al contenido


Cargar un StringGrid con un file Intelhex.


  • Por favor identifícate para responder
24 respuestas en este tema

#21 seoane

seoane

    Advanced Member

  • Administrador
  • 1.259 mensajes
  • LocationEspaña

Escrito 09 noviembre 2008 - 01:02

Aqui hay un problema:


delphi
  1.   for j:= 1 to StringGrid1.RowCount - 1 do


Se pasa y no se detiene cuando llega a la ultima linea(row) del stringgrid.

:o Estas seguro de eso, (RownCount - 1) es el índice de la ultima fila. O estas diciendo que dephi se confunde y sigue incrementando J  :-\
  • 0

#22 Guest_Jose Fco_*

Guest_Jose Fco_*
  • Visitante

Escrito 09 noviembre 2008 - 02:19

Yo creo un stringgrid de 256 lineas y luego al llenarlo con el file Intelhex se pasa de esa linea.
Dejame hacer otra prueba y postear una foto de lo que digo.
Un Saludo.

#23 Guest_Jose Fco_*

Guest_Jose Fco_*
  • Visitante

Escrito 09 noviembre 2008 - 02:31

Aqui esta todo el codigo donde estoy trabajando solo con un stringgrid:


delphi
  1. type
  2.   TBuffer = array[$0000..$FFFF] of Byte;
  3.   TForm1 = class(TForm)
  4.   StringGrid1: TStringGrid;
  5.     Button1: TButton;
  6.     OpenDialog1: TOpenDialog;
  7.   procedure FormShow(Sender: TObject);
  8.     procedure Button1Click(Sender: TObject);
  9.   private
  10.   procedure InicializaGridBuffer;
  11.     { Private declarations }
  12.   public
  13.     { Public declarations }
  14.   end;
  15. const
  16.   BufferSize = 4096;
  17. var
  18.   Form1: TForm1;
  19.   Cuantos, CuentaB : Integer;
  20.  
  21. implementation
  22.  
  23. {$R *.dfm}
  24. procedure TForm1.InicializaGridBuffer;
  25. var
  26.     i,r,j,k,l: integer;
  27. begin
  28.   StringGrid1.ColWidths[0] := 35;
  29.   StringGrid1.Cells[0,0] := 'Addr';
  30.  
  31.   for i := 0 to 15 do
  32.     StringGrid1.Cells[i+1,0] := IntTohex(i,2);
  33.     for j := 0 to (BufferSize div 16)-1 do    // (BufferSize div 16)
  34.     begin
  35.       k := j;
  36.       StringGrid1.Height := StringGrid1.Height + 1;
  37.       StringGrid1.RowCount := StringGrid1.RowCount + 1;
  38.       StringGrid1.Cells[0,k+1] := IntToHex(l,4);
  39.       l := l + 16;
  40.       for r := 1 to 16 do
  41.       StringGrid1.Cells[r,k+1] := IntToHex(255,2);
  42.  
  43. end;
  44. end;
  45. procedure TForm1.FormShow(Sender: TObject);
  46. begin
  47.   InicializaGridBuffer;
  48.   CuentaB := 0;
  49. end;
  50. // Insertamos la linea de datos en un buffer
  51. function Insertar(Str: String; var Buffer: TBuffer): String;
  52. var
  53. i,j,k: Integer;
  54. begin
  55. Result:= EmptyStr;
  56. Str:= Trim(Str);
  57. if Copy(Str,1,1) = ':' then
  58. if TryStrToInt('$' + Copy(Str,2,2),i) then
  59. if Length(Str) = ((2*i) + 11) then
  60. if TryStrToInt('$' + Copy(Str,4,4),j) then
  61. if TryStrToInt('$' + Copy(Str,8,2),k) then
  62. if k = 0 then
  63. begin
  64. Str:= Copy(Str,10,2*i);
  65. for k:= j to (j + i - 1) do
  66. begin
  67. Buffer[k]:= StrToInt('$' + Copy(Str,1,2));
  68. Delete(Str,1,2);
  69. end;
  70. end;
  71. end;
  72. procedure TForm1.Button1Click(Sender: TObject);
  73. var
  74. i,j: Integer;
  75. Buffer: TBuffer;
  76. begin
  77. if OpenDialog1.Execute then
  78. begin
  79. //for i:= 1 to StringGrid1.RowCount - 1 do
  80. //StringGrid1.Rows[i].Clear;
  81. with TStringList.Create do
  82. try
  83. LoadFromFile(OpenDialog1.Filename);
  84. // Llenamos todo el buffer con $FF
  85. FillChar(Buffer,Sizeof(Buffer),#$FF);
  86. // Leemos el archivo linea a linea e insertamos los datos en el buffer
  87. for i:= 0 to Count - 1 do
  88. Insertar(Strings[i],Buffer);
  89. for j:= 1 to StringGrid1.RowCount - 1 do
  90. for i:= 1 to StringGrid1.ColCount - 1 do
  91. StringGrid1.Cells[i,j]:= IntToHex(Buffer[((j-1)*16)+i-1],2);
  92. finally
  93. Free;
  94. end;
  95. end;
  96. end;
  97.  
  98. end.


Cuando cuando copilo todo esta bien, crea el stringgrid deceado.Pero de solo hacer click en el boton se desforma el stringgrid y se hace mas grande(mas lineas)
Es a lo que me refiero.Entonces pues delphi ve que le decimos hasta la ultima linea menos una y el es obediente.Algo al hacer click al boton y antes de selecionar file alguno incrementa las lineas al grid.

Un Saludo.

#24 seoane

seoane

    Advanced Member

  • Administrador
  • 1.259 mensajes
  • LocationEspaña

Escrito 09 noviembre 2008 - 02:53

Pero de solo hacer click en el boton se desforma el stringgrid y se hace mas grande(mas lineas)

¿A que boton te refieres?, si es el de ejecutar de delphi, fijate que que el procedure InicializaGridBuffer estas aumentando en 256 filas el stringgrid.
  • 0

#25 Guest_Jose Fco_*

Guest_Jose Fco_*
  • Visitante

Escrito 09 noviembre 2008 - 03:09

Yo copilo y esto es lo que sale:
Imagen Enviada
Luego al solo darle al boton que tengo en el form esto es lo que pasa:
Imagen Enviada
Se incrementa o mejor dicho creo que se crea otra vez el stringgrid pero sin address.(FF) solo F en las grid.
En algun lado del codigo esta entendiendo eso.

Un Saludo.




IP.Board spam blocked by CleanTalk.