Ver Mensaje Individual
  #1  
Antiguo 06-05-2014
elmago00 elmago00 is offline
Miembro
NULL
 
Registrado: ago 2013
Posts: 86
Reputación: 11
elmago00 Va por buen camino
Exclamation Ayuda a pasar este código a firemonkey.

hola,
anteriormente el señor ecfisa.
me ayudo a crear un editor hexadecimal, funciona bien en VCL. pero necesito tenerlo en firemonkey.
Código Delphi [-]
implementation 
 
procedure DumpFile(aFileName:TFileName; SG: TStringGrid; const BPF: Word);
var
  c, i, r: integer;
  ascii: string;
  aux: Byte;
begin
  with TMemoryStream.Create do
  try
    LoadFromFile(aFileName);
    // configurar StringGrid
    SG.Options:= SG.Options - [goVertLine] - [goHorzLine];
    SG.Font.Name:= 'Courrier';
    SG.Font.Size:= 10;
    SG.ColWidths[0]:= 80;
    SG.Cells[0,0]:= 'Offset(h)';
    SG.ColCount:= BPF+2;
    SG.ColWidths[SG.ColCount-1]:= SG.Canvas.TextWidth('X') * BPF;
    SG.Cells[SG.ColCount-1,0]:= 'ASCII';
    for i:= 0 to BPF-1 do
    begin
      SG.ColWidths[i+1]:= 30;
      SG.Cells[i+1,0]:= IntToHex(i,2);
    end;
    SG.RowCount:= Size div BPF;
    // cargar en StringGrid
    Seek(0, soBeginning);
    c:= 0;
    r:= SG.FixedRows;
    while c < Size do
    begin
      SG.Cells[0, r]:= Format('%s',[IntToHex(c, 8)]);
      ascii:= EmptyStr;
      i:= 0;
      while (i < BPF)and(i+c < Size) do
      begin
        Read(aux, SizeOf(Byte));
        SG.Cells[i+1,r]:= IntToHex(aux,2);
        if aux = 0 then aux := 46;
        ascii:= ascii + Chr(aux);
        Inc(i);
      end;
      SG.Cells[SG.ColCount-1,r]:= Format('%s',[ascii]);
      Inc(c, BPF);
      Inc(r);
    end;
  finally
    Free;
  end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  ComboBox1.Items.CommaText:= '8,10,16,24,32,48,64,128,255';
  ComboBox1.ItemIndex:= 2;
end;

procedure TForm1.btnFileClick(Sender: TObject);
begin
  with OpenDialog1 do
  begin
    Filter:= '*.*';
    if Execute then
    begin
      Caption:= FileName;
      DumpFile(FileName, StringGrid1,
        StrToInt(ComboBox1.Items[ComboBox1.ItemIndex]) );
    end;
  end;
end;



procedure SaveDump(aFileName:TFileName; SG: TStringGrid);
var
  c,r: Integer;
  s: string;
begin
  with TStringList.Create do
  try
    for r:= SG.FixedRows to SG.RowCount-1 do
    begin
      s:= '';
      for c:= 0 to SG.ColCount-1 do s:= s + SG.Cells[c,r] + ' ';
      SetLength(s,Length(s)-1);
      Add(s);
    end;
    SaveToFile(aFileName);
  finally
    Free;
  end;
end;
...

procedure TForm1.btnSaveToTxtClick(Sender: TObject);
begin
  with SaveDialog1 do
  begin
    Filter:= '*.txt';
    DefaultExt:= '*.txt';
    if Execute then
      SaveDump(FileName, StringGrid1);
  end;
end;

sera posible pasar este código a firemonkey, sin usar un Control StringGrid. es decir que se almacene en una variable, y no en StringGrid. pero sino, lo mas importante para mi es pasar este código a firemonkey. yo hago el resto.

muchas gracias por su ayuda.
Responder Con Cita