Registriert seit: 29. Mai 2002
37.621 Beiträge
Delphi 2006 Professional
|
Re: In eine Datei
10. Nov 2003, 18:59
Diese Routine hängt eine Datei an eine andere dran:
Delphi-Quellcode:
function AttacheFile(StubFile, AttacheFile: string): Integer;
var
hStubFile, hAttacheFile: THandle;
MemBuffer: array[0..BLOCKSIZE - 1] of Byte;
StubFileSize, AttacheFileSize, BytesRead, BytesToRead, BytesWritten,
TotalBytesWritten: Int64;
PercentDone, PercentDoneOld: Cardinal;
begin
BytesRead := 1;
TotalBytesWritten := 0;
PercentDoneOld := 0;
hStubFile := FileOpen(StubFile, $0001);
if hStubFile <> INVALID_HANDLE_VALUE then
begin
StubFileSize := GetFileSize(pointer(StubFile));
FileSeek(hStubFile, StubFileSize, 0);
hAttacheFile := FileOpen(AttacheFile, 0);
AttacheFileSize := GetFileSize(pointer(AttacheFile));
if hAttacheFile <> INVALID_HANDLE_VALUE then
begin
SendMessage(hApp, EFM_FILENAME, 0, lParam(PChar(AttacheFile)));
while TotalBytesWritten < AttacheFileSize do
begin
BytesToRead := CalcBytesToRead(BytesRead, AttacheFileSize);
BytesRead := FileRead(hAttacheFile, MemBuffer, BytesToRead);
BytesWritten := FileWrite(hStubFile, MemBuffer, BytesRead);
TotalBytesWritten := TotalBytesWritten + BytesWritten;
PercentDone:= (TotalBytesWritten * 100) div AttacheFileSize;
if PercentDone <> PercentDoneOld then
begin
SendMessage(hApp, EFM_PROGRESS, 0, PercentDone);
PercentDoneOld := PercentDone;
end;
ProcessMessages(hApp);
end;
end;
FileClose(hAttacheFile);
end;
FileClose(hStubFile);
SendMessage(hApp, EFM_FINISH, GetLastError(), lParam(PChar(AttacheFile)));
result := GetLastError();
end;
Michael Ein Teil meines Codes würde euch verunsichern.
|
|
Zitat
|