Club Delphi  
    FTP   CCD     Buscar   Trucos   Trabajo   Foros

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

Respuesta
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 07-05-2014
Avatar de nlsgarcia
[nlsgarcia] nlsgarcia is offline
Miembro Premium
 
Registrado: feb 2007
Ubicación: Caracas, Venezuela
Posts: 2.206
Poder: 21
nlsgarcia Tiene un aura espectacularnlsgarcia Tiene un aura espectacular
elmago00,

Cita:
Empezado por elmago00
...solo detallen las propiedades que tiene este código pero en FireMonkey...
Revisa este código:
Código Delphi [-]
unit Unit1;

interface

uses
  System.SysUtils, System.Types, System.UITypes, System.Rtti, System.Classes,
  System.Variants, System.UIConsts, FMX.Types, FMX.Controls, FMX.Forms, FMX.Dialogs,
  FMX.StdCtrls, FMX.ListBox, FMX.Layouts, FMX.Grid;

type

  TColumnAccess = class(TColumn)
  end;

  TForm1 = class(TForm)
    StringGrid1: TStringGrid;
    ComboBox1: TComboBox;
    OpenDialog1: TOpenDialog;
    SaveDialog1: TSaveDialog;
    Button1: TButton;
    Button2: TButton;
    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.fmx}

procedure DumpFile(aFileName:TFileName; SG: TStringGrid; const BPF: Word);
var
  c, i, r: Integer;
  Ascii: String;
  Aux: Byte;
  Col, Row: Integer;
  CellCtrl: TStyledControl;

begin

  with TMemoryStream.Create do
  try

    LoadFromFile(aFileName);

    // Configurar StringGrid

    SG.ShowHeader := False;
    SG.ShowHorzLines := False;
    SG.ShowVertLines := False;

    for i := 1 to BPF + 2 do
       SG.AddObject(TStringColumn.Create(nil));

    SG.RowCount:= Size div BPF;

    for Row := 0 to SG.RowCount - 1 do
    begin
       for Col := 0 to SG.ColumnCount - 1 do
       begin

          Application.ProcessMessages;

          CellCtrl := TColumnAccess(SG.Columns[Col]).CellControlByRow(Row);
          if ( CellCtrl <> nil ) and (CellCtrl is TTextCell) then
          begin

             TTextCell(CellCtrl).StyledSettings := [];
             TTextCell(CellCtrl).Font.Family := 'Courrier New';
             TTextCell(CellCtrl).Font.Size := 10;
             TTextCell(CellCtrl).FontColor := claBlack;
             TTextCell(CellCtrl).Font.Style := [];
             TTextCell(CellCtrl).TextAlign := TTextAlign.taCenter;

             if (Col = 0) then
                SG.Columns[Col].Width := 80;

             if (Col <> SG.ColumnCount - 1) and (Col <> 0) then
                SG.Columns[Col].Width := 30;

             if (Col = SG.ColumnCount - 1) then
                SG.Columns[Col].Width := SG.Canvas.TextWidth('X') * BPF;

          end;
       end;
    end;

    SG.Cells[0,0]:= 'Offset(h)';
    SG.Cells[SG.ColumnCount-1,0]:= 'ASCII';

    for i:= 0 to BPF-1 do
    begin
      SG.Cells[i+1,0]:= IntToHex(i,2);
    end;

    // Cargar StringGrid

    Seek(0, soBeginning);
    c:= 0;
    r:= 1;
    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.ColumnCount-1,r]:= Format('%s',[Ascii]);
      Inc(c, BPF);
      Inc(r);
    end;
  finally
    Free;
  end;
end;

// Salvar StringGrig a Archivo TXT
procedure SaveDump(aFileName:TFileName; SG: TStringGrid);
var
  c,r: Integer;
  s: String;
begin
  with TStringList.Create do
  try
    for r:= 0 to SG.RowCount-1 do
    begin
      s:= '';
      for c:= 0 to SG.ColumnCount-1 do s:= s + SG.Cells[c,r] + ' ';
      SetLength(s,Length(s)-1);
      Add(s);
    end;
    SaveToFile(aFileName);
  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.Button1Click(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 TForm1.Button2Click(Sender: TObject);
begin
  with SaveDialog1 do
  begin
    Filter:= '*.txt';
    DefaultExt:= '*.txt';
    if Execute then
      SaveDump(FileName, StringGrid1);
  end;
end;

end.
El código anterior en Delphi XE4 bajo Windows 7 Professional x32, es la implementación del código del Msg #1 en FireMonkey HD, como se muestra en la siguiente imagen:



Espero sea útil

Nelson.

Última edición por nlsgarcia fecha: 07-05-2014 a las 08:11:55.
Responder Con Cita
  #2  
Antiguo 07-05-2014
elmago00 elmago00 is offline
Miembro
NULL
 
Registrado: ago 2013
Posts: 86
Poder: 11
elmago00 Va por buen camino
gracias Nelson por ayudarme. ya es de madrugada y ustedes me siguen ayudando. mil gracias.

tu código solo tiene un contraste, yo como te dije antes, uso XE3.
y me da dos errores el primero dice:

TTextCell no contiene ningún miembro con el nombre StyledSettings.
es esta linea
Código Delphi [-]
TTextCell(CellCtrl).StyledSettings := [];

veo que tu usas algunas clases que XE3 no están disponibles, como ser: FMX.StdCtrls;

el segundo problema es que abre el archivo pero en blanco, el StringGrid no muestra nada.

perdona tanta molestia, pero cuando el cerebro no da, no queda de otra, que pedir ayuda.
Responder Con Cita
  #3  
Antiguo 07-05-2014
elmago00 elmago00 is offline
Miembro
NULL
 
Registrado: ago 2013
Posts: 86
Poder: 11
elmago00 Va por buen camino
intente no usar la opcion
Código Delphi [-]
TTextCell(CellCtrl).StyledSettings := [];
Pero ahora me permite cerrar la venta. : )
Responder Con Cita
  #4  
Antiguo 07-05-2014
Avatar de nlsgarcia
[nlsgarcia] nlsgarcia is offline
Miembro Premium
 
Registrado: feb 2007
Ubicación: Caracas, Venezuela
Posts: 2.206
Poder: 21
nlsgarcia Tiene un aura espectacularnlsgarcia Tiene un aura espectacular
elmago00,

Cita:
Empezado por elmago00
...abre el archivo pero en blanco, el StringGrid no muestra nada...

...intente no usar la opción...TTextCell(CellCtrl).StyledSettings := []...
Pregunto:

1- ¿De que tamaño es el archivo en cuestión?.

2- ¿Puedes abrir otros archivos?.

3- ¿La eliminación de la opción mencionada es la única modificación al código propuesto en el Msg #11?.

Espero sea útil

Nelson.
Responder Con Cita
  #5  
Antiguo 07-05-2014
Avatar de nlsgarcia
[nlsgarcia] nlsgarcia is offline
Miembro Premium
 
Registrado: feb 2007
Ubicación: Caracas, Venezuela
Posts: 2.206
Poder: 21
nlsgarcia Tiene un aura espectacularnlsgarcia Tiene un aura espectacular
elmago00,

Cita:
Empezado por elmago00
...abre el archivo pero en blanco, el StringGrid no muestra nada...

...intente no usar la opción...TTextCell(CellCtrl).StyledSettings := []...
Es probable que el archivo probado sea muy grande (La lectura es Byte a Byte), y por ello tarda en ser visualizado, eso se soluciona con la inclusión de Application.ProcessMessages en el ciclo de carga del TStringGrid.

Revisa este código:
Código Delphi [-]
unit Unit1;

interface

uses
  System.SysUtils, System.Types, System.UITypes, System.Rtti, System.Classes,
  System.Variants, System.UIConsts, FMX.Types, FMX.Controls, FMX.Forms, FMX.Dialogs,
  FMX.StdCtrls, FMX.ListBox, FMX.Layouts, FMX.Grid;

type

  TForm1 = class(TForm)
    StringGrid1: TStringGrid;
    ComboBox1: TComboBox;
    OpenDialog1: TOpenDialog;
    SaveDialog1: TSaveDialog;
    Button1: TButton;
    Button2: TButton;
    StatusBar1: TStatusBar;
    Label1: TLabel;
    Button3: TButton;
    Button4: TButton;
    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure DumpFile(aFileName:TFileName; SG: TStringGrid; const BPF: Word);
    procedure SaveDump(aFileName:TFileName; SG: TStringGrid);
    procedure Button3Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  CancelProcess : Boolean;

implementation

{$R *.fmx}

procedure TForm1.DumpFile(aFileName:TFileName; SG: TStringGrid; const BPF: Word);
var
  c, i, r, b : Integer;
  Ascii: String;
  Aux: Byte;
  Col : Integer;

begin

  with TMemoryStream.Create do
  try

    LoadFromFile(aFileName);

    Caption:= Format('FileName = %s , FileSize = %d Bytes', [aFileName, Size]);

    // Configurar StringGrid

    SG.ShowHeader := False;
    SG.ShowHorzLines := False;
    SG.ShowVertLines := False;

    for i := 1 to BPF + 2 do
       SG.AddObject(TStringColumn.Create(nil));

    SG.RowCount:= Size div BPF;

    for Col := 0 to SG.ColumnCount - 1 do
    begin

        if (Col = 0) then
           SG.Columns[Col].Width := 80;

        if (Col <> SG.ColumnCount - 1) and (Col <> 0) then
           SG.Columns[Col].Width := 30;

        if (Col = SG.ColumnCount - 1) then
           SG.Columns[Col].Width := SG.Canvas.TextWidth('X') * BPF;

    end;

    SG.Cells[0,0]:= 'Offset(h)';
    SG.Cells[SG.ColumnCount-1,0]:= 'ASCII';

    for i:= 0 to BPF-1 do
    begin
      SG.Cells[i+1,0]:= IntToHex(i,2);
    end;

    // Cargar en StringGrid

    Seek(0, soBeginning);
    c:= 0;
    r:= 1;
    b := 0;

    while c < Size do
    begin

      Application.ProcessMessages;

      if CancelProcess then
      begin
         CancelProcess := False;
         Break;
      end;

      SG.Cells[0, r]:= Format('%s',[IntToHex(c, 8)]);
      Ascii:= EmptyStr;
      i:= 0;

      while (i < BPF) 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);
        if (b < Size) then Inc(b);
      end;

      SG.Cells[SG.ColumnCount-1,r]:= Format('%s',[Ascii]);
      Inc(c, BPF);
      Inc(r);
      Label1.Text := Format('Procesado Byte %d de %d',[b, Size]);

    end;

  finally

    Free;

  end;

end;

// Salvar StringGrig a TXT
procedure TForm1.SaveDump(aFileName:TFileName; SG: TStringGrid);
var
  c,r: Integer;
  s: String;
begin
  with TStringList.Create do
  try
    for r:= 0 to SG.RowCount-1 do
    begin
      s:= '';
      for c:= 0 to SG.ColumnCount-1 do s:= s + SG.Cells[c,r] + ' ';
      SetLength(s,Length(s)-1);
      Add(s);
    end;
    SaveToFile(aFileName);
  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;

// Carga un Archivo en Modo Hexadecimal en un StringGrid
procedure TForm1.Button1Click(Sender: TObject);
begin
  with OpenDialog1 do
  begin
    Filter:= '*.*';
    if Execute then
    begin
      DumpFile(FileName, StringGrid1,
        StrToInt(ComboBox1.Items[ComboBox1.ItemIndex]) );
    end;
  end;
end;

// Salva un Archivo en Modo Hexadecimal en un StringGrid a TXT
procedure TForm1.Button2Click(Sender: TObject);
begin
  with SaveDialog1 do
  begin
    Filter:= '*.txt';
    DefaultExt:= '*.txt';
    if Execute then
      SaveDump(FileName, StringGrid1);
  end;
end;

// Cancela Carga de un Archivo en Modo Hexadecimal en un StringGrid
procedure TForm1.Button3Click(Sender: TObject);
begin
   CancelProcess := True;
end;

// Inicializa el StringGrid
procedure TForm1.Button4Click(Sender: TObject);
var
   i : Integer;
begin
   StringGrid1.RowCount := 0;
   for i := StringGrid1.ColumnCount - 1 downto 0 do
         StringGrid1.Columns[i].DisposeOf;
end;

end.
El código anterior en Delphi XE4 bajo Windows 7 Professional x32, es la versión 2 del código propuesto en el Msg #11, con unas pequeños cambios en el manejo del Visualizador de Archivos en Hexadecimal en FireMonkey, como se muestra en la siguiente imagen:



El código esta disponible en : Visualizador de Archivos en Hexadecimal en FireMonkey

Espero sea útil

Nelson.

Última edición por nlsgarcia fecha: 07-05-2014 a las 18:52:10.
Responder Con Cita
  #6  
Antiguo 07-05-2014
elmago00 elmago00 is offline
Miembro
NULL
 
Registrado: ago 2013
Posts: 86
Poder: 11
elmago00 Va por buen camino
muchas gracias al fin lo conseguí, se demora un poco, pero no importa. muchas gracias Nelson
para que fuera compatible con XE3 lo hice asi.

Código Delphi [-]
procedure DumpFile(aFileName:TFileName; SG: TStringGrid; const BPF: Word);
var
  c, i, r, b : Integer;
  Ascii: String;
  Aux: Byte;
  Col : Integer;

begin

  with TMemoryStream.Create do
  try

    LoadFromFile(aFileName);



    // Configurar StringGrid

    SG.ShowHeader := False;
    SG.ShowHorzLines := False;
    SG.ShowVertLines := False;

    for i := 1 to BPF + 2 do
       SG.AddObject(TStringColumn.Create(nil));

    SG.RowCount:= Size div BPF;

    for Col := 0 to SG.ColumnCount - 1 do
    begin

        if (Col = 0) then
           SG.Columns[Col].Width := 80;

        if (Col <> SG.ColumnCount - 1) and (Col <> 0) then
           SG.Columns[Col].Width := 30;

        if (Col = SG.ColumnCount - 1) then
           SG.Columns[Col].Width := SG.Canvas.TextWidth('X') * BPF;

    end;

    SG.Cells[0,0]:= 'Offset(h)';
    SG.Cells[SG.ColumnCount-1,0]:= 'ASCII';

    for i:= 0 to BPF-1 do
    begin
      SG.Cells[i+1,0]:= IntToHex(i,2);
    end;

    // Cargar en StringGrid

    Seek(0, soBeginning);
    c:= 0;
    r:= 1;
    b := 0;

    while c < Size do
    begin

      Application.ProcessMessages;

      if CancelProcess then
      begin
         CancelProcess := False;
         Break;
      end;

      SG.Cells[0, r]:= Format('%s',[IntToHex(c, 8)]);
      Ascii:= EmptyStr;
      i:= 0;

      while (i < BPF) 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);
        if (b < Size) then Inc(b);
      end;

      SG.Cells[SG.ColumnCount-1,r]:= Format('%s',[Ascii]);
      Inc(c, BPF);
      Inc(r);


    end;

  finally

    Free;

  end;

end;

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


{guardar}

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



{abrir}

procedure TForm12.Button6Click(Sender: TObject);
   var
   valor:string;
begin
    valor:='16';
 with OpenDialog1 do
  begin
    Filter:= '*.*';
    if Execute then
    begin
      Caption:= FileName;
      DumpFile(FileName, StringGrid1,
        StrToInt(valor));
    end;
  end;
end;

{cancelar}

procedure TForm12.Button26Click(Sender: TObject);
begin
CancelProcess := True;
end;

gracias a Ecfisa y Nelson.
Responder Con Cita
Respuesta



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
ayuda con este codigo kurono Varios 5 02-04-2014 00:25:11
Se estrena este foro sobre FireMonkey Neftali [Germán.Estévez] FireMonkey 9 09-11-2012 13:05:30
ayuda con este codigo kurono Varios 4 13-06-2008 01:03:29
necesito ayuda con este codigo kurono Varios 4 06-05-2008 07:02:07
procedimiento almacenado ayuda con este codigo pipecato Varios 5 16-12-2005 12:24:34


La franja horaria es GMT +2. Ahora son las 00:18:46.


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