2011-08-09 3 views
1

Delphi XE를 사용하여, TZipMaster 1.91 (최신)Delphi TZipMaster - Find 메서드를 사용하는 방법?

찾기 기능에 전달 된 FSpec arg와 일치하는 첫 번째 파일 이름의 파일 이름을 가져 오려고합니다. 그러나이 함수를 호출 할 때 액세스 위반이 발생합니다.

var 
    DBBakFl : String; 
    d : Integer; 
    begin 
    ZipMaster191.ZipFileName := 'myzip.zip'; 

    try 
     DBBakFl := ZipMaster191.Find('*.FBK', d).FileName; 
    except 
     raise Exception.Create('Find raised an exception'); 
    end; 

도움을 주시면 감사하겠습니다.

편집 : 구성 요소 작성자 인 러셀 피터스 (Russell Peters)의 이메일에서 거의 즉각적인 답변을 받았습니다. 내 대답보기.

답변

1

:

나는 당신이 AV를 얻을 놀라게하고 있지 않다

var 
    Idx: Integer; 
    Entry: TZMDirEntry; 
    DBBakFl : String; 
begin 
try 
    Idx := -1; // search from beginning, starts at Idx + 1 
    Index := ZipMaster191.Find('*.FBK', Idx); 
    if Index <> nil then 
     DBBakFl := Index .FileName; 
except 
    raise Exception.Create('Find raised an exception'); 
end; 

OR 
var 
    Idx: Integer; 
    DBBakFl : String; 
begin 
try 
    Idx := -1; // search from beginning, starts at Idx + 1 
    if ZipMaster191.Find('*.FBK', Idx) <> nil then 
     DBBakFl := ZipMaster191[Idx].FileName; 
except 
    raise Exception.Create('Find raised an exception'); 
end; 

OR 

var 
    Idx: Integer; 
    DBBakFl : String; 
begin 
try 
    Idx := -1; // search from beginning, starts at Idx + 1 
    ZipMaster191.Find('*.FBK', Idx) ; 
    if Idx >= 0 then 
     DBBakFl := ZipMaster191[Idx].FileName; 
except 
    raise Exception.Create('Find raised an exception'); 
end; 

In a loop it is easy 

Idx := -1; 
while ZipMaster191.Find('*.FBK', Idx) <> nil do 
begin 
     DBBakFl := ZipMaster191[Idx].FileName; 

러셀 피터

1

찾기 호출이 실패하면 유효한 TZMDirEntry 인스턴스가 반환되지 않으므로 FileName 속성에 액세스 할 수 없습니다.

찾기 결과를 변수에 할당하고 해당 속성이나 메서드에 액세스하기 전에 유효성을 검사하십시오. 어쩌면 이런 식으로. 문서에서는 TZMDirEntry가 추상 클래스임을 보여 주므로 대신 자손 클래스를 사용해야 할 수도 있습니다. 같은 시도

var 
    DBBakFl : String; 
    d : Integer; 
    lDirEntry: TZMDirEntry; 
    begin 
    ZipMaster191.ZipFileName := 'myzip.zip'; 

    lDirEntry := ZipMaster191.Find('*.FBK', d); 
    if Assigned(lDirEntry) then 
     DBBakFl := lDirEntry.FileName 
    else 
     ShowMessage('file not found'); 
+0

예. 예. 제 질문은 '어떻게 찾기 작업을 할 수 있습니까?'였습니다. –

+0

먼저 찾기의 반환 값을 확인하십시오. 나는 내 대답을 테스트되지 않은 제안으로 업데이트했다. –

+0

@ 브루스 - 테스트되지 않은 제안을 입력하는 동안! –

2

: 효과적으로 노력하고있는 것을 발견으로

var 
    DBBakFl : String; 
    d : Integer; 
    DirEntry: TZMDirEntry; 
begin 
    ZipMaster191.ZipFileName := 'myzip.zip'; 

    DirEntry := ZipMaster191.Find('*.FBK', d); 
    if Assigned(DirEntry) then 
    begin 
    DBBakF1 := DirEntry.FileName; 
    .... 
    end; 

이 실패는 전무 TZMDirEntry에서 파일 이름을 얻는 것입니다. 기본적으로 동일하게 : 나는 이메일 구성 요소의 저자 중 한, 러셀 피터스에서 거의 즉각적인 대답을 얻었다 전송

var 
    DBBakFl : String; 
    DirEntry: TZMDirEntry; 
begin 

    DirEntry := nil; 
    DBBakF1 := DirEntry.FileName; 
end; 
+0

아카이브 내에 FBK 파일이 있어도 Find가 nil을 반환하는 이유는 무엇입니까? –

+0

그것은 다른 질문이며 대답하기 쉽지 않은 질문입니다. –

+0

@Rudy : 저자 인 러셀 피터스 (Russell Peters)가 직접 대답을 얻었으니이 페이지에 답을 게시 할 수있는 권한을 기다리는 중입니다. –

관련 문제