Ir para conteúdo

POWERED BY:

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

Rodrigo C. Lopes

Stream para vetor de bytes

Recommended Posts

Olá galera, gostaria de saber se existe alguma forma de se armazerar umdados de uma variavel Tstream(Imagem, Video, Texto) em um vetor de bytesEx.:type TPerson = record Name: string[50]; vorname: string[50]; end; TComputer = record Name: string[30]; cpu: string[30]; end;var Form1: TForm1; Person: TPerson; Computer: TComputer; Stream: TFileStream;implementation{$R *.DFM}//Speichern resp. Erstellen von Datei//Save or create the fileprocedure TForm1.Button1Click(Sender: TObject);begin try Stream := TFileStream.Create('c:\test.dat', fmOpenReadWrite); except Stream := TFileStream.Create('c:\test.dat', fmCreate); end; //2 Einträge pro Record //save 2 records for TPerson and TComputer Person.Name := 'Grossenbacher'; Person.vorname := 'Simon'; Stream.WriteBuffer(Person, SizeOf(TPerson)); Person.Name := 'Stutz'; Person.vorname := 'Thomas'; Stream.WriteBuffer(Person, SizeOf(TPerson)); Computer.Name := 'Delphi'; Computer.cpu := 'Intel'; Stream.WriteBuffer(Computer, SizeOf(TComputer)); Computer.Name := 'Win'; Computer.cpu := 'AMD'; Stream.WriteBuffer(Computer, SizeOf(TComputer)); Stream.Free;end;//lädt alle daten von TPerson in listbox1 und//daten von TComputer in Listbox2//load records from TPerson to listbox1 and//load records from TComputer to listbox2procedure TForm1.Button2Click(Sender: TObject);var i: Integer;begin try // nur lesen öffnen //open read only Stream := TFileStream.Create('c:\test.dat', fmOpenRead); except ShowMessage('Datei konnte nicht geladen werden.'); Exit; end; //variable i auf anzahl Einträge setzen //set variable i to the record count //Einlesen von TPerson //Read records TPerson for i := 2 downto 1 do begin Stream.ReadBuffer(Person, SizeOf(TPerson)); Listbox1.Items.Add(Person.vorname + ' ' + Person.Name); end; //Einlesen von TComputer //Read Records TComputer for i := 2 downto 1 do begin Stream.ReadBuffer(Computer, SizeOf(TComputer)); Listbox2.Items.Add(Computer.Name + ' ' + Computer.cpu); end; Stream.Free;end;Nesse exemplo eu queria inserir um campo no registro do tipo, Tbitmap por exemplo ou o que acharia omais certo, um vetor de bytes, onde a variavel stream seria convertida para o mesmo.Abração galera

Compartilhar este post


Link para o post
Compartilhar em outros sites

Olá galera, gostaria de saber se existe alguma forma de se armazerar umdados de uma variavel Tstream(Imagem, Video, Texto) em um vetor de bytesEx.:type TPerson = record Name: string[50]; vorname: string[50]; end; TComputer = record Name: string[30]; cpu: string[30]; end;var Form1: TForm1; Person: TPerson; Computer: TComputer; Stream: TFileStream;implementation{$R *.DFM}//Speichern resp. Erstellen von Datei//Save or create the fileprocedure TForm1.Button1Click(Sender: TObject);begin try Stream := TFileStream.Create('c:\test.dat', fmOpenReadWrite); except Stream := TFileStream.Create('c:\test.dat', fmCreate); end; //2 Einträge pro Record //save 2 records for TPerson and TComputer Person.Name := 'Grossenbacher'; Person.vorname := 'Simon'; Stream.WriteBuffer(Person, SizeOf(TPerson)); Person.Name := 'Stutz'; Person.vorname := 'Thomas'; Stream.WriteBuffer(Person, SizeOf(TPerson)); Computer.Name := 'Delphi'; Computer.cpu := 'Intel'; Stream.WriteBuffer(Computer, SizeOf(TComputer)); Computer.Name := 'Win'; Computer.cpu := 'AMD'; Stream.WriteBuffer(Computer, SizeOf(TComputer)); Stream.Free;end;//lädt alle daten von TPerson in listbox1 und//daten von TComputer in Listbox2//load records from TPerson to listbox1 and//load records from TComputer to listbox2procedure TForm1.Button2Click(Sender: TObject);var i: Integer;begin try // nur lesen öffnen //open read only Stream := TFileStream.Create('c:\test.dat', fmOpenRead); except ShowMessage('Datei konnte nicht geladen werden.'); Exit; end; //variable i auf anzahl Einträge setzen //set variable i to the record count //Einlesen von TPerson //Read records TPerson for i := 2 downto 1 do begin Stream.ReadBuffer(Person, SizeOf(TPerson)); Listbox1.Items.Add(Person.vorname + ' ' + Person.Name); end; //Einlesen von TComputer //Read Records TComputer for i := 2 downto 1 do begin Stream.ReadBuffer(Computer, SizeOf(TComputer)); Listbox2.Items.Add(Computer.Name + ' ' + Computer.cpu); end; Stream.Free;end;Nesse exemplo eu queria inserir um campo no registro do tipo, Tbitmap por exemplo ou o que acharia omais certo, um vetor de bytes, onde a variavel stream seria convertida para o mesmo.Abração galera

Como ninguem respondeu e eu achei um código que funciona, aí vai:procedure TForm1.Button1Click(Sender: TObject);var Origin, Destination :file of byte; Buffer :array[0..4096] of char; Read :integer; Length :longint;begin AssignFile(Origin,'c:\kk\uno.exe'); reset(Origin); AssignFile(Destination,'c:\kk\dos.exe'); rewrite(Destination); Length:=FileSize(Origin); ProgressBar1.Max:=Length; ProgressBar1.Min:=0; while Length >0 do begin BlockRead(Origin,Buffer[0],SizeOf(Buffer),Read); Length:=Length-Read; BlockWrite(Destination,Buffer[0],Read); ProgressBar1.Position:=ProgressBar1.Position+Read; end; CloseFile(Origin); CloseFile(Destination);end; http://forum.imasters.com.br/public/style_emoticons/default/clap.gif

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.