procedure TForm1.FormCreate(Sender: TObject);
begin
memo1.ScrollBars := ssBoth; // COLOCA LAS DOS BARRAS DE DESPLAZAMIENTO
stringgrid1.ColCount := 5; // INDICA QUE DEBE TENER 5 COLUMNAS
//CONFIGURACIONES OPCIONALES
stringgrid1.Options := [goFixedVertLine,goFixedHorzLine,goVertLine,goHorzLine,goRangeSelect,goColSizing];
stringgrid1.Anchors := [akLeft,akTop,akRight,akBottom];
memo1.Anchors := [akLeft,akTop,akRight];
end;
procedure TForm1.Button1Click(Sender: TObject);
var
j: integer;
begin
{ EL PROGRAMA LEE UN ARCHIVO *.HEX DESDE LA UNIDAD C:\
EL FORMATO DEL ARCHIVO ES EL SIGUIENTE:
:BBBBBBBB BBBBBBBB BBBBBBBB BBBBBBBB BBBBBBBBBB
SE VE QUE LA PRIMERA LINEA COMIENZA CON DOS PUNTOS, Y LA ULTIMA FILA TIENE
10 NUMEROS, Y EL RESTO TIENEN 8 NUMEROS.}
opendialog1.InitialDir := getcurrentdir; //INDICA LA RUTA DEL DIRECTORIO DONDE ESTA EL PROGRAMA
opendialog1.Filter := 'ARCHIVO HEX|*.hex'; //TIPO DE ARCHIVO QUE VA A ABRIR EL DIALOGO
if opendialog1.Execute then
begin
//LEE EL ARCHIVO Y LO ESCRIBE EN EL MEMO1
memo1.Lines.LoadFromFile(opendialog1.FileName);
//CONFIGURA EL NUMERO DE FILAS DEL STRINGGRID1
stringgrid1.RowCount := memo1.Lines.Count + 1;
//PARA CADA FILA SE LEE Y SELECCIONA LA PORCION DE TEXTO PARA
//COLOCARLA EN LAS CELDAS DEL STRINGGRID1
for j := 0 to stringgrid1.RowCount do
begin
stringgrid1.Cells[0,j+1] := ansimidstr(memo1.Lines[j],2,8);
stringgrid1.Cells[1,j+1] := ansimidstr(memo1.Lines[j],11,8);
stringgrid1.Cells[2,j+1] := ansimidstr(memo1.Lines[j],20,8);
stringgrid1.Cells[3,j+1] := ansimidstr(memo1.Lines[j],29,8);
stringgrid1.Cells[4,j+1] := ansimidstr(memo1.Lines[j],38,10);
end;
end;
{
utilizar
USES StrUtils
Delphi syntax:
function AnsiMidStr(const AText: AnsiString; const AStart, ACount: Integer): AnsiString;
}
end;
Suerte.procedure TForm1.FormCreate(Sender: TObject);
begin
stringgrid1.ColCount:= 17;
stringgrid1.RowCount:= 5;
stringgrid1.DefaultColWidth:=32;
stringgrid1.DefaultRowHeight:=16;
stringgrid1.Cells[0,0]:='Offset';
stringgrid1.Cells[1,0]:='0';
stringgrid1.Cells[2,0]:='1';
stringgrid1.Cells[3,0]:='2';
stringgrid1.Cells[4,0]:='3';
stringgrid1.Cells[5,0]:='4';
stringgrid1.Cells[6,0]:='5';
stringgrid1.Cells[7,0]:='6';
stringgrid1.Cells[8,0]:='7';
stringgrid1.Cells[9,0]:='8';
stringgrid1.Cells[10,0]:='9';
stringgrid1.Cells[11,0]:='A';
stringgrid1.Cells[12,0]:='B';
stringgrid1.Cells[13,0]:='C';
stringgrid1.Cells[14,0]:='D';
stringgrid1.Cells[15,0]:='E';
stringgrid1.Cells[16,0]:='F';
stringgrid1.Cells[0,1]:='$00';
stringgrid1.Cells[0,2]:='$10';
stringgrid1.Cells[0,3]:='$20';
stringgrid1.Cells[0,4]:='$30';
// MyHex := inttohex(255,2);
end;
function TForm1.HexToInt(Value: String): Integer;
begin
Result := StrToInt('$' + Value);
end;
procedure TForm1.savebin_buttonClick(Sender: TObject);
//Boton Crear fichero Bin con filtro .bin
begin
savedialog1.InitialDir := getcurrentdir;
savedialog1.Filter := 'ARCHIVO BIN|*.bin';
savedialog1.Execute;
if savedialog1.FileName <> '' then savebin(savedialog1.FileName);
end;
Procedure TForm1.Savebin(sFilename : String);
var
byteArray : array[1..16] of byte;
I, J, K, dato_bin : Integer;
hFile : File;
begin
Assignfile(hFile, sFileName);
rewrite(hFile, 16); //Usamos bloques de 16 bytes
with StringGrid1 do
for I := 1 to RowCount - 1 do
begin
K := 1;
for J:= 1 to ColCount - 1 do
begin
dato_bin:=hextoint(Cells[J,I]);
bytearray[K]:= dato_bin; //cargamos 16 bytes en el array
K:=K+1;
end;
blockwrite(hfile,bytearray,1); // Escribe bloque de 16 bytes
end;
CloseFile(hFile);
End;
procedure TForm1.openBinClick(Sender: TObject);
//Boton Guardar fichero Bin con filtro .bin
begin
opendialog1.InitialDir := getcurrentdir;
opendialog1.Filter := 'ARCHIVO BIN|*.bin';
opendialog1.Execute;
if opendialog1.FileName<>'' then loadbin(opendialog1.FileName);
end;
procedure TForm1.loadbin( Nom_Fichero:string);
var
Fichero:file;
I, J: Integer;
dato_bin : array[1..16] of byte;
begin
assignfile(fichero, Nom_Fichero);
reset(fichero,16); //Cargamos 16 bytes de cada vez ( 1 fila )
with StringGrid1 do
for I := 1 to RowCount - 1 do
begin
blockread(fichero,dato_bin,1); //Lee 1 bloque de 16 bytes
for J:= 1 to ColCount - 1 do
begin
Cells[J,I]:= inttohex(dato_bin[J],2); //Pone 16 bytes en la fila
end;
end;
closefile(fichero);
end;
end.
Hola Astrocar,
Muy interesante este componente para un editor Hex.
HAcer un swap, ¿te refieres a cada byte del fichero? es decir si tienes en $0001 un byte de valor $FE, hacerle un swap y convertir el valor en $EF ¿no?
En ese caso lo más sencillo es coger el valor, convertirlo a string, cambiar de posición los dos caracteres y convertirlo al formato de origen en el componente (integer o hex). En caso de un swap a todo el bin, usar un bucle con un contador bidimensional tipo contador[i,j]
Te está quedando muy bien la aplicación. Ya nosmostrarás algo del programador :)
Salu2
Saludos y voy hacer un codigo a mi manera lko que si tengo que investigar mejor es como manejar esos archivos binarios porque siguen siendo binario solo que ahora tiene un formato de identificacion como el caso del intel hex y asi otros formatos que ahora no los tocare como son el e2p que lo usa el software de ponyprog y el s19 que lo usa la gente de motorola y pare de contar pero como ya les indique siguen siendo binarios secuenciales lo otro es llevarlo o interpretarlo conm un formato tal.
No deberíais perderos la novela del amigo Diego: "El fichero .HEX explicado (http://www.todopic.com.ar/foros/index.php?topic=23342.0)"Interesante post, no lo habia visto,
Yo si lo habia leido de hecho de ese post es que tengo claro el formato intel mi drama es llevar eso a delphi.No deberíais perderos la novela del amigo Diego: "El fichero .HEX explicado (http://www.todopic.com.ar/foros/index.php?topic=23342.0)"Interesante post, no lo habia visto,
Gracias Nocturno.
Salu2
Esta muy interesante este tema, de lo unico que tengo duda, es porque el foro no envia las notificaciones de los temas que he solicitado notificacion, pues este tema lo habia solicitado, y lo deje con unos cuantos post, pero regreso de algun tiempo y ya habian avanzado bastante y ni enterado, lo mismo pasa con otro post de programadores, tampoco me notifica.Hola eto eso que comentas sobre que te avise sobre las respuestas del post no lo he revisado pero tomo este mismo respiuesta como prueba haber si te notifica de un a nueva respuesta y asumo que esa notificacion te la envia a tu correo que tienes suscrito en el foro o cuando entres nuevamente al foro te avise nose como solicitas ese aviso de todas maneras lo pondre en practica para ver eso ya que es muy importante eso de avisarle sobre los post que uno lleva una secuencia asi no se pierde de lo adelando y como va el tema en si.
Hola astrocar, pues esta vez si me notificó, gracias., acabo de bajar el componente que subiste se ve interesante, lo probaré más tarde.Ok me alegro entonce caso cerrado lo de la notificacion y centremos entonce en el tema.
Saludos.
Pd. para que te notificque , cuando estas viendo un tema, en la parte donde esta el boton de respuesta, al lado aparece el boton de notificar, y en tu perfil configuras a donde y como quieres que te notifique.