Stream prueba

pascal:
Program TestStream;

uses classes;

Var Stream : TFileStream;
    S,T : String;

begin
  S:='ABCDEFGHIJKLMNOPQRSTUVWXYZ';
  T:=S;
  Writeln ('Creating stream.');
  Stream:=TFileStream.Create('Test2.dat',fmcreate);
  Writeln ('Initial Size : ',Stream.Size);
  Writeln ('Initial Position : ',Stream.Position);
  Stream.WriteByte  (1);
  Stream.WriteWord  (2);
  Stream.WriteDWord (3);
  Stream.WriteBuffer (S[1],Length(S));
  Writeln ('Stream Size is : ',Stream.Size);
  Stream.Seek(0,soFromBeginning);
  If Stream.ReadByte<>1 then  Writeln ('First byte not 1');
  If Stream.ReadWord<>2 then  Writeln ('First word not 2');
  If Stream.ReadDWord<>3 then Writeln ('First DWord not 3');
  If Stream.Read(T[1],Length(S))<>Length(S) then
    Writeln ('Couldn''t read string.');
  Writeln ('Second pass.');
  Stream.WriteByte  (1);
  Stream.WriteWord  (2);
  Stream.WriteDWord (3);
  Stream.WriteBuffer (S[1],Length(S));
  Writeln ('Stream Size is : ',Stream.Size);
  Writeln ('Stream Position is : ',Stream.Position);
  Writeln ('Freeing stream.');
  Stream.Free;
  Writeln ('Creating stream Read-Only');
  Stream:=TFileStream.Create('Test2.dat',fmOpenRead);
  Writeln ('Stream Size is : ',Stream.Size);
  Stream.Seek(0,soFromBeginning);
  If Stream.ReadByte<>1 then  Writeln ('First byte not 1');
  If Stream.ReadWord<>2 then  Writeln ('First word not 2');
  If Stream.ReadDWord<>3 then Writeln ('First DWord not 3');
  If Stream.Read(T[1],Length(S))<>Length(S) then
    Writeln ('Couldn''t read string.');
  If Stream.ReadByte<>1 then  Writeln ('Second byte not 1');
  If Stream.ReadWord<>2 then  Writeln ('Second word not 2');
  If Stream.ReadDWord<>3 then Writeln ('Second DWord not 3');
  If Stream.Read(T[1],Length(S))<>Length(S) then
    Writeln ('Couldn''t read string.');
  Writeln ('Stream Size is : ',Stream.Size);
  Writeln ('Stream Position is : ',Stream.Position);
  Stream.Free;
end.
  $Log: fstream.pp,v $
  Revision 1.4  2005/02/14 17:13:18  peter
    * truncate log

}
 
¿Ya le viste algún error? Dejanos tu correción ;-)

Antes de comentar: Gran parte de los ejercicios propuestos no tienen librerías debido a que Wordpress elimina los tags HTML. Si sabes/tienes/conoces las librerías que hacen falta, déjalo en los comentarios.

Otro punto antes de comentar, Si vas a sugerir un segmento de código en algún lenguaje debes hacerlo así:

De esta manera el código sale coloreado.

Otro punto importante para muchos que sienten que se les ignora: Todos los comentarios los reviso y en su debido momento los apruebo, pero ojo con el último párrafo.

Para poner los símbolos de las librerías sin que desaparezcan, debes escribir los símbolos de mayor > y menor qué < con su entidad HTML correspondiente, así como el símbolo de &

Mis Algoritmos se reserva el derecho de alterar, publicar o no los comentarios así como cambiar estas reglas de uso.

Si estas de acuerdo, adelante puedes comentar :)

P.D. No le hago tareas a nadie, mejor hagan la mía :P