Me tomé la molestia de colocar tu código entre las etiquetas delphi, por favor, úsalas con más frecuencia
.
Código Delphi
[-]
unit Server1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
Dialogs, IdBaseComponent, IdComponent, IdTCPServer, Gauges,IdContext,
IdCustomTCPServer, IdGlobal, StdCtrls;
type
TForm1 = class(TForm)
Server1: TIdTCPServer; Gauge1: TGauge;
Memo1: TMemo; procedure Server1Execute(AContext: TIdContext);
procedure FormCreate(Sender: TObject);
private
public
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Server1Execute(AContext: TIdContext);
var
s: string;
F: TFileStream;
BufSize,i : Integer;
A:file of byte; buff : TidBytes;
Buffer:Array [0..1023] of byte; Leidos, Longitud: Integer; begin
AssignFile(A,'recibe.dat');
F := TFileStream.Create( ExtractFilePath( Application.ExeName ) +'prueba.txt', fmCreate ); F.Position:=0;
Longitud:= strtoint(Acontext.Connection.IOHandler.Readln); Leidos:= 0; rewrite(A); Gauge1.MinValue:=Leidos; Gauge1.Progress:=Gauge1.MinValue;
Gauge1.MaxValue:=Longitud;
while Longitud > 0 do begin
Leidos:= strtoint(AContext.Connection.IOHandler.Readln); AContext.Connection.IOHandler.ReadBytes(buff,sizeOf(Buffer),false);
BytesToRaw(Buff, Buffer, sizeOf(Buffer));
s:=bytestostring(buff,sizeof(buff));
F.Write(s[1],length(s));
BlockWrite(A,Buff,Leidos);
Gauge1.Progress:=Gauge1.Progress + Leidos; Longitud:= Longitud - Leidos;
end;
try
CloseFile(A);
F.Free; except
Showmessage('No he cerrado el fichero');
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
Server1.Active:=true; end;
end.
Saludos.