인트라넷의 파일에 액세스하는 응용 프로그램이 있습니다. 사용자는 네트워크에있는 서버에서 로컬 PC로 파일을 복사 할 수 있습니다. 초기 연결에 문제가 발생했습니다. 즉 애플리케이션이 시작될 때. 사용자가 데이터베이스에서 파일을 검색합니다. 그가 다운로드 할 파일을 찾으면 그는 이름을 클릭하고 응용 프로그램은 파일을 다운로드합니다. 첫 다운로드 작업은 다운로드를 시작하고 진행률 막대를 보는 데 약 8-12 초 정도 걸립니다. 다음 다운로드는 거의 즉시 이루어집니다. 파일 크기는 1MB에서 15MB 사이입니다. 필요가 없습니다 어쩌면 fileExists ... 질식의 포인트가 될 수있는 곳 나는 확실하지 않다서버에서 로컬 드라이브로 파일 복사 - 파일을 가져 오는 속도가 느려질 수 있습니까?
const
projectFilesURL = '\\IntranetServer\Directory\filesLocation\';
procedure form1.GetSelectedFile(const fileName: string);
var
sourceFile: string;
begin
{ \\IntranetServer\Directory\filesLocation\userSelectedFile.zip}
sourceFile := projectFilesURL + fileName;
if FileExists(sourceFile) then
begin
fileCopy(fileName);
lblSearching.Hide;
AnimSearching.Hide;
end
else
MessageDlg(
'The file was not found on the server'
, mtInformation, [mbCancel], 0);
end;
end;
procedure form1.fileCopy(const sourceFile: string);
var
SourceF, DestF: file;
Buf: array [0 .. 1023] of byte;
NumRead, FSize, BytesCopied: Integer;
destinationPathandFile: string;
begin
destinationPathandFile := ExtractFilePath(ParamStr(0))
+ exportPath + sourceFile;
try
AssignFile(SourceF, projectFilesURL + sourceFile);
AssignFile(DestF, destinationPathandFile);
FileMode := 0;
Reset(SourceF, 1);
Rewrite(DestF, 1);
FSize := FileSize(SourceF);
BytesCopied := 0;
fileCopyProgress.Percent := 0;
while not Eof(SourceF) do
begin
BlockRead(SourceF, Buf, SIZEOF(Buf), NumRead);
BlockWrite(DestF, Buf, NumRead);
Inc(BytesCopied, NumRead);
fileCopyProgress.Percent := (BytesCopied * 100) div FSize;
Application.ProcessMessages;
end;
CloseFile(SourceF);
CloseFile(DestF);
except
on E: Exception do
begin
raise Exception.Create('Error occured while copying a file');
Exit;
end;
end;
:
여기 내 코드입니다. 파일이 서버에 있거나 없기 때문에 ... 예외를 던질 가능성이 있습니다. 제안 사항에 감사드립니다. 감사합니다, 통해 getSelected에서
링크 Joe에게 감사드립니다. 좋은 예입니다. 내 프로그램으로 구현할 수 있는지 알 수 있습니다. – Greener