2013-05-24 4 views
0

프로그램을 개발 중이며 그 위에 StringGrid가 있습니다. 특정 버튼을 누르면 내 프로그램은 stringgtid를 c : \ myfolder \ tab9.txt에 저장합니다. 언젠가 그리드에 많은 행이 있고 시간이 걸릴 수 있기 때문에 저장 프로세스가 끝날 때까지 남은 시간을 나타내는 진행률 표시 줄을 넣고 싶습니다.StringGrid를 저장하는 동안 진도 표시 줄 진행

procedure SaveSG(StringGrid:TStringGrid; const FileName:TFileName); 
var 
    f: TextFile; 
    i,k: Integer; 
begin 
    AssignFile(f, FileName); 
    Rewrite(f); 
    with StringGrid do 
    begin 
    Writeln(f, ColCount); // Write number of Columns 
    Writeln(f, RowCount); // Write number of Rows 
    for i := 0 to ColCount - 1 do // loop through cells of the StringGrid 
     for k := 0 to RowCount - 1 do 
     Writeln(F, Cells[i, k]); 
     end; 
    CloseFile(F); 
end; 

나는이 방법으로 프로 시저를 호출 : SaveSG(StringGrid1,'c:\myfolder\myfile.txt');이 코드를 사용하고 있습니다. 문제는 저장 진행 상황을 나타내는 진행률 막대를 수행하는 방법을 이해하지 못한다는 것입니다. 지금은 ProgressBar1.Position:=0ProgressBar1.Max:=FileSize만을 선언했습니다. 의견 있으십니까?

+1

이 작업을 수행하려면 * 제대로 * 파일을 자체 스레드에로드 한 다음 일정 간격으로 진행률 표시 줄에 메시지를 보내야합니다. –

답변

3

몇 개의 세포를 말하고 있습니까? 주요 병목 현상은 각 셀에 파일을 작성하는 대신 버퍼링 된 쓰기를 수행한다는 것입니다.

TStringList를 TStringGrid의 데이터로 채우고 TStringList.SaveToFile() 메서드를 사용하는 것이 좋습니다.

내가 10,000,000 세포 (10,000 행 X 1000 열)와 StringGrid에 절차에 따라 테스트 한, 그것은 초 미만의 디스크에 데이터를 저장합니다

procedure SaveStringGrid(const AStringGrid: TStringGrid; const AFilename: TFileName); 
var 
    sl : TStringList; 
    C1, C2: Integer; 
begin 
    sl := TStringList.Create; 
    try 
    sl.Add(IntToStr(AStringGrid.ColCount)); 
    sl.Add(IntToStr(AStringGrid.RowCount)); 
    for C1 := 0 to AStringGrid.ColCount - 1 do 
     for C2 := 0 to AStringGrid.RowCount - 1 do 
     sl.Add(AStringGrid.Cells[C1, C2]); 
    sl.SaveToFile(AFilename); 
    finally 
    sl.Free; 
    end; 
end; 
+0

감사합니다. 매우 유용합니다. –