Thank you Benny,
I will go through your code and try to learn something from it.
It will definitely come in handy in the future. However, it doesn't solve my current problem, when the MEMO control element is needed, because the data is exported to the clipboard from another application and it probably won't work if it has to be saved in TXT before importing.
But in the end I tried an option that didn't occur to me right away and the problem is solved. As Bart wrote a bit above, you need to set the position of the ProgressBar twice, and after each setting you need to call the code from Handoko. Changed code in the
PB demo project (in the attachment) - total number of lines in MEMO 139,678 converted in 5s.
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, ComCtrls,
LCLIntf, LCLType;
type
{ TfrmForm1 }
TfrmForm1 = class(TForm)
Button1: TButton;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Memo1: TMemo;
ProgressBar1: TProgressBar;
procedure Button1Click(Sender: TObject);
private
public
end;
var
frmForm1: TfrmForm1;
implementation
{$R *.lfm}
{ TfrmForm1 }
procedure TfrmForm1.Button1Click(Sender: TObject);
var
i: Integer;
begin
Label5.Caption := ''; // text READY after ending the loop (visual indication only - not needed)
Label5.Font.Color := clRed;
Label4.Caption := FormatFloat('# ### ###', Memo1.Lines.Count);
ProgressBar1.Min := 0;
ProgressBar1.Max := Memo1.Lines.Count;
for i := 0 to Memo1.Lines.Count - 1 do
begin
Label2.Caption := FormatFloat('# ### ###', i + 1);
// the first setting of the ProgressBar
ProgressBar1.Position := i+1;
if i < (Memo1.Lines.Count-1) then
begin
if (i mod 50) <> 0 then Continue; // this line is for better performance
end;
Application.ProcessMessages;
// the second ProgressBar setting
ProgressBar1.Position := i;
if i < (Memo1.Lines.Count-1) then
begin
if (i mod 50) <> 0 then Continue; // this line is for better performance
end;
Application.ProcessMessages;
if GetKeyState(VK_ESCAPE) < 0 then Break; // Allow user cancellation
end;
Label5.Caption := 'Ready';
end;
end.
Thank you all for your willingness to help