X
xiongshao
Unregistered / Unconfirmed
GUEST, unregistred user!
我想通过mscomm传输文件.把声音文件导入,打开了,该怎么传输呀,下面是我写的,一传就关闭程序了...谁有源程序让我看看吧
procedure TForm1.Button2Click(Sender: TObject);
var
i :integer;
FromF: file;
NumRead: Integer;
Buf: array[1..2048] of char;
begin
if OpenDialog1.Execute then { Display Open dialog box }
begin
AssignFile(FromF, OpenDialog1.FileName);
Reset(FromF, 1); { Record size = 1 }
Canvas.TextOut(10, 10, 'Copying ' + IntToStr(FileSize(FromF))
+ ' bytes...');
repeat
BlockRead(FromF, Buf, SizeOf(Buf), NumRead);
for i:=1 to 2048 do
mscomm1.Output:=buf;
until (NumRead = 0)
end;
CloseFile(FromF);
end;
procedure TForm1.MSComm1Comm(Sender: TObject);
var Buf: array[1..2048] of olevariant;
i:integer;
ToF: file;
NumWritten: Integer;
buffer: array[1..2048] of variant ;
begin
for i:=1 to 2048 do
begin
if mscomm1.CommEvent=2 then
begin
buf:=mscomm1.input;
buffer:=buf;
BlockWrite(ToF, Buf,SizeOf(Buf), NumWritten);
end;
分不多了...
procedure TForm1.Button2Click(Sender: TObject);
var
i :integer;
FromF: file;
NumRead: Integer;
Buf: array[1..2048] of char;
begin
if OpenDialog1.Execute then { Display Open dialog box }
begin
AssignFile(FromF, OpenDialog1.FileName);
Reset(FromF, 1); { Record size = 1 }
Canvas.TextOut(10, 10, 'Copying ' + IntToStr(FileSize(FromF))
+ ' bytes...');
repeat
BlockRead(FromF, Buf, SizeOf(Buf), NumRead);
for i:=1 to 2048 do
mscomm1.Output:=buf;
until (NumRead = 0)
end;
CloseFile(FromF);
end;
procedure TForm1.MSComm1Comm(Sender: TObject);
var Buf: array[1..2048] of olevariant;
i:integer;
ToF: file;
NumWritten: Integer;
buffer: array[1..2048] of variant ;
begin
for i:=1 to 2048 do
begin
if mscomm1.CommEvent=2 then
begin
buf:=mscomm1.input;
buffer:=buf;
BlockWrite(ToF, Buf,SizeOf(Buf), NumWritten);
end;
分不多了...