[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 873
  • Last Modified:

Using a progressbar to show loading text in Memo

Is there a way to use a progress bar to show the progress of a file being loaded or save into/out a TMemo or RichText Component.
0
brad554
Asked:
brad554
1 Solution
 
jsextonCommented:
Try using BlockRead and increment the progress bar when each block is loaded.
0
 
xpherCommented:
Listening
0
 
interCommented:
Hi,

if you use the original LoadFromFile mechanism, there is no way. But you may do it with hand as jsexton suggested. However why do you need such thing? did you read text files that took Megabytes?

igor
0
Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

 
intheCommented:
hi,
here is something earl f glynn posted a while ago using the tgauge component with a text file:

 the TGauge sample from Delphi -- even if you're reading a textfile.
 
If you're trying to read a textfile, you first need to know how big the file is. Open the file in binary mode just so you can use FileSize (See GetFileSize below).
 
Once you have the filesize, just count the bytes as you read them from the text file and occasionaly update the gauage to show progress.  See the code fragment below, ReadLoadData, that I regularly use to show progress reading a 500-900 KB file.  It's not perfect, but I think you'll find that it is a good enough heuristic approach to show progress while loading a file.
 
=====================================================================================
  FUNCTION GetFileSize(CONST FileName:  STRING):  LongInt;
    VAR
      RawFile    :  FILE OF Byte;
  BEGIN
    TRY
      AssignFile (RawFile, FileName);
      Reset (RawFile);
      RESULT := FileSize(RawFile);
      CloseFile (RawFile);
    EXCEPT
      ShowMessage ('Fatal Error:  Cannot open ' + FileName + ' (binary)');       Halt
    END
  END {GetFileSize};
 
 
 
 
  PROCEDURE ReadLoadData (VAR LoadGauge:  TGauge);
    VAR
      Buffer      :  ARRAY[1..8192] OF CHAR;
      ByteCount  :  LongInt;
      LineCount  :  LongInt;
      LoadFile    :  TextFile;
      FileName    :  STRING;
      NewRecord  :  TUnitRecord;
      OK          :  BOOLEAN;
      RecordDelta :  WORD;
      Size        :  LongInt;
      TextLine    :  STRING;
  BEGIN
    FileName := GetDBGADSalias + 'Megawatt\LOAD.TXT';
    Size := GetFileSize(FileName);
 
    {Use heuristic to estimate 1% of file}
    RecordDelta := Size DIV (100 * 102);    {approx 1% of file}
    IF  RecordDelta  < 10
    THEN RecordDelta := 10;                {lower bound of RecordDelta}
 
    TRY
      AssignFile (LoadFile, FileName);
      SetTextBuf(LoadFile, Buffer);
      Reset (LoadFile);                    {open the file}
    EXCEPT
      ShowMessage ('Fatal Error:  Cannot open ' + FileName + ' (text)');       Halt
    END;
 
    READLN (LoadFile, TextLine);    {burn the header line of comments}     ByteCount := 260;              {approx size of header}
    LineCount := 1;
 
    WHILE NOT EOF(LoadFile)
    DO BEGIN
      READLN (LoadFile, TextLine);
 
      ...
 
 
 
      INC (LineCount);    
      INC (ByteCount, LENGTH(TextLine)+2);    {Add 2 for CR + LF in binary file}
 
      {You may want to update every N lines, or use some other heuristic}       IF  LineCount MOD RecordDelta = 0
      THEN LoadGauge.Progress := ROUND(100 * ByteCount / Size);
 
    END;
 
    ...
    LoadGauge.Progress := 100;
    ...
    CloseFile (LoadFile);
 
  END {ReadLoadData};



Regards Barry
0
 
RBertoraCommented:
Following...
0
 
intheCommented:
hello
  did it not help ??
0
 
brad554Author Commented:
Sorry about the late response. Had no time to try out your reponse until now thanks for the help
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now