issamdnn
10-12-2009, 09:16 AM
تستخدم هذه الطريقة عادة من أجل إرسال ملف عبر أي منفذ من منافذ الجهاز وهي طريقة فعالة وقمت
بتجربتها بنفسي ... لأكثر من مرة
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls,Grids;
type
TForm1 = class(TForm)
Button1: TButton;
StringGrid1: TStringGrid;
OpenDialog1: TOpenDialog;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
iFileHandle: Integer;
iFileLength: Integer;
iBytesRead: Integer;
Buffer:array[1..770049] of char ;//لا يتم حجزها ضمن بداية البرنامج
i: Longint ;
begin
if OpenDialog1.Execute then
begin
// GetMem(Buffer,100);
//try
iFileHandle := FileOpen(OpenDialog1.FileName, fmOpenRead);
iFileLength := FileSeek(iFileHandle,0,2);
//SetLength(buffer,iFileLength+1);
FileSeek(iFileHandle,0,0);
//Buffer := PChar(AllocMem(iFileLength + 1));
iBytesRead := FileRead(iFileHandle, Buffer, iFileLength);
FileClose(iFileHandle);
for i := 1 to iBytesRead-1 do
begin
StringGrid1.RowCount := StringGrid1.RowCount + 1;// طباعة البايتات لمعرفتها
StringGrid1.Cells[1,i+1] := Buffer[i];
StringGrid1.Cells[2,i+1] := IntToStr(Integer(Buffer[i]));
end ;
// finally
// FreeMem(Buffer);
end ;
end ;
//end;
end.
بتجربتها بنفسي ... لأكثر من مرة
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls,Grids;
type
TForm1 = class(TForm)
Button1: TButton;
StringGrid1: TStringGrid;
OpenDialog1: TOpenDialog;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
iFileHandle: Integer;
iFileLength: Integer;
iBytesRead: Integer;
Buffer:array[1..770049] of char ;//لا يتم حجزها ضمن بداية البرنامج
i: Longint ;
begin
if OpenDialog1.Execute then
begin
// GetMem(Buffer,100);
//try
iFileHandle := FileOpen(OpenDialog1.FileName, fmOpenRead);
iFileLength := FileSeek(iFileHandle,0,2);
//SetLength(buffer,iFileLength+1);
FileSeek(iFileHandle,0,0);
//Buffer := PChar(AllocMem(iFileLength + 1));
iBytesRead := FileRead(iFileHandle, Buffer, iFileLength);
FileClose(iFileHandle);
for i := 1 to iBytesRead-1 do
begin
StringGrid1.RowCount := StringGrid1.RowCount + 1;// طباعة البايتات لمعرفتها
StringGrid1.Cells[1,i+1] := Buffer[i];
StringGrid1.Cells[2,i+1] := IntToStr(Integer(Buffer[i]));
end ;
// finally
// FreeMem(Buffer);
end ;
end ;
//end;
end.