Recent

Author Topic: ProgressBar  (Read 4559 times)

seghele0

  • Full Member
  • ***
  • Posts: 173
ProgressBar
« on: October 29, 2021, 02:04:13 pm »
I'm trying to put a text in the "Progressbar", please help.
 :-[

Code: Pascal  [Select][+][-]
  1. procedure TForm1.Timer1Timer(Sender: TObject);
  2. begin
  3.   ProgressBar1.Position := ProgressBar1.Position +10;
  4.   if ProgressBar1.Position = 100 then
  5.   begin
  6.     Timer1.Enabled:=False;
  7.     ProgressBar1.Position:=0;
  8.     ProgressBar1.Cursor:= crDefault;
  9.   end;
  10. end;
  11.  
  12. procedure TForm1.Button1Click(Sender: TObject);
  13. begin
  14.    ProgressBar1.Show;
  15.    ProgressBar1.Cursor:= crHourGlass;
  16.    Timer1.Enabled:=True;
  17.    ProgressBar1.BarShowText:= True;
  18.    ProgressBar1.Caption := 'WAIT...';
  19.  
  20. end;                        

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: ProgressBar
« Reply #1 on: October 29, 2021, 02:16:46 pm »
The LCL uses your OS's native widget for most controls.
Some OSs do not support progress bar text display (Mac and Linux if memory serves correctly).

Zvoni

  • Hero Member
  • *****
  • Posts: 2319
Re: ProgressBar
« Reply #2 on: October 29, 2021, 02:27:06 pm »
Write your own. There should be enough sample code lying around here in the forum
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

AlexTP

  • Hero Member
  • *****
  • Posts: 2386
    • UVviewsoft
Re: ProgressBar
« Reply #3 on: October 29, 2021, 03:52:09 pm »

winni

  • Hero Member
  • *****
  • Posts: 3197
Re: ProgressBar
« Reply #4 on: October 29, 2021, 04:58:06 pm »
Hi!

And another hack:

Code: Pascal  [Select][+][-]
  1. uses ....., LCLIntf;
  2.  
  3. ....
  4. procedure TForm1.Button1Click(Sender: TObject);
  5. var
  6.   Can: TCanvas;
  7.   hwnd: THandle;
  8.   DC: HDC;
  9.  
  10. begin
  11.   Can:=TCanvas.Create;
  12.    hwnd:= ProgressBar1.Handle;
  13.    DC:=GetDC(hwnd);
  14.    Can.Handle := DC;
  15.    can.Brush.Style:=bsClear;
  16.    can.TextOut(0,0,'Hi Folks');
  17.    can.free;
  18.    ReleaseDC(hwnd, DC);
  19. end;

Winni

jamie

  • Hero Member
  • *****
  • Posts: 6090
Re: ProgressBar
« Reply #5 on: October 30, 2021, 01:56:45 am »
of course one could simply create a windows control like a Static text and assign its parent to that of the progress bar. Also have its owner from the ProgressBar...  :D
The only true wisdom is knowing you know nothing

seghele0

  • Full Member
  • ***
  • Posts: 173
Re: ProgressBar
« Reply #6 on: October 30, 2021, 01:13:34 pm »
Winni,

Thanks for your response.
But I I get several 'errors'!

Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls,
  9.   LCLIntf;
  10.  
  11. type
  12.  
  13.   { TForm1 }
  14.  
  15.   TForm1 = class(TForm)
  16.     Button1: TButton;
  17.     Button2: TButton;
  18.     procedure Button1Click(Sender: TObject);
  19.     procedure Button2Click(Sender: TObject);
  20.   private
  21.  
  22.   public
  23.  
  24.   end;
  25.  
  26. var
  27.   Form1: TForm1;
  28.  
  29. implementation
  30.  
  31. {$R *.frm}
  32.  
  33. { TForm1 }
  34.  
  35. procedure TForm1.Button2Click(Sender: TObject);
  36. begin
  37.    Close;
  38. end;
  39.  
  40. procedure TForm1.Button1Click(Sender: TObject);
  41. var
  42.   Can: TCanvas;
  43.   hwnd: THandle;
  44.   DC: HDC;
  45. begin
  46.   Can:=TCanvas.Create;
  47.    hwnd:= ProgressBar1.Handle;
  48.    DC:=GetDC(hwnd);
  49.    Can.Handle := DC;
  50.    can.Brush.Style:=bsClear;
  51.    can.TextOut(0,0,'Hi Folks');
  52.    can.free;
  53.    ReleaseDC(hwnd, DC);
  54. end;
  55.  
  56. end.                

Quote
Hint: (11030) Start of reading config file C:\codetyphon\fpc\fpc64\bin\x86_64-win64\fpc.cnf
Hint: (11031) End of reading config file C:\codetyphon\fpc\fpc64\bin\x86_64-win64\fpc.cnf
Free Pascal Compiler version 3.3.1 [2020/04/14] for x86_64
Copyright (c) 1993-2020 by Florian Klaempfl and others
(1002) Target OS: Win64 for x64
(3104) Compiling project1.ppr
(3104) Compiling unit1.pas
C:\CT-PROGS-710\TEST-PROGRESSBAR-5\unit1.pas(44,7) Error: (5000) Identifier not found "HDC"
C:\CT-PROGS-710\TEST-PROGRESSBAR-5\unit1.pas(44,10) Error: (5007) Error in type definition
C:\CT-PROGS-710\TEST-PROGRESSBAR-5\unit1.pas(47,11) Error: (5000) Identifier not found "ProgressBar1"
C:\CT-PROGS-710\TEST-PROGRESSBAR-5\unit1.pas(49,20) Error: (4025) Incompatible type for arg no. 1: Got "<erroneous type>", expected "QWord"
C:\codetyphon\typhon\lcl\units\x86_64-win64\graphics.ppu:canvas.inc(1625,19) Hint: (5039) Found declaration: SetHandle(QWord);
C:\CT-PROGS-710\TEST-PROGRESSBAR-5\unit1.pas(53,22) Error: (4025) Incompatible type for arg no. 2: Got "<erroneous type>", expected "QWord"
C:\codetyphon\typhon\lcl\units\x86_64-win64\lclintf.ppu:winapi.inc(808,10) Hint: (5039) Found declaration: ReleaseDC(QWord;QWord):LongInt;
unit1.pas(58) Fatal: (10026) There were 5 errors compiling module, stopping
Fatal: (1018) Compilation aborted
Error: C:\codetyphon\fpc\fpc64\bin\x86_64-win64\ppcx64.exe returned an error exitcode


winni

  • Hero Member
  • *****
  • Posts: 3197
Re: ProgressBar
« Reply #7 on: October 30, 2021, 01:25:46 pm »
Hi!

If you want to write on an ProgressBar then it is necessary to put a ProgressBar on your Form.

Winni

seghele0

  • Full Member
  • ***
  • Posts: 173
Re: ProgressBar
« Reply #8 on: October 30, 2021, 01:37:01 pm »
Sorry, I forgot it.  :-X
Code: Pascal  [Select][+][-]
  1.   TForm1 = class(TForm)
  2.     Button1: TButton;
  3.     Button2: TButton;
  4.     ProgressBar1: TProgressBar;
  5.  
  6.     procedure Button1Click(Sender: TObject);
  7.     procedure Button2Click(Sender: TObject);    

But I still get the errors.
 :(

winni

  • Hero Member
  • *****
  • Posts: 3197
Re: ProgressBar
« Reply #9 on: October 30, 2021, 01:54:20 pm »
Hi!

For HDC you have to include LCLtype in the uses section.

Winni

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: ProgressBar
« Reply #10 on: October 30, 2021, 02:50:50 pm »
Perhaps your components originate from CodeTyphon?
Winni's instructions assume a standard LCL TProgressBar.

jamie

  • Hero Member
  • *****
  • Posts: 6090
Re: ProgressBar
« Reply #11 on: October 30, 2021, 03:11:45 pm »
Code: Pascal  [Select][+][-]
  1. procedure TForm1.FormCreate(Sender: TObject);
  2. begin
  3.  LclIntF.SetParent(StaticText1.Handle,ProgressBar1.Handle);
  4.  StaticText1.Left := 2;
  5.  StaticText1.Top := 2;
  6.  StaticText1.Caption := 'Showing in Progress Bar now';
  7. end;                                              
  8.  

Just drop a TStatictext on the form and TProgreeBar, define it at any time time..

Make sure you have the "lclIntf" unit included..
The only true wisdom is knowing you know nothing

jamie

  • Hero Member
  • *****
  • Posts: 6090
Re: ProgressBar
« Reply #12 on: October 30, 2021, 04:20:49 pm »
and another way around it is this..
Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ComCtrls, StdCtrls,LCLIntf;
  9.  
  10. type
  11.   TProgressBar = Class(ComCtrls.TProgressBar)
  12.     TheText:TStaticText;
  13.     constructor Create(aOwner:TComponent); Override;
  14.   end;
  15.  
  16.   { TForm1 }
  17.  
  18.   TForm1 = class(TForm)
  19.     ProgressBar1: TProgressBar;
  20.     procedure FormCreate(Sender: TObject);
  21.   private
  22.  
  23.   public
  24.  
  25.   end;
  26.  
  27. var
  28.   Form1: TForm1;
  29.  
  30. implementation
  31.  
  32. {$R *.lfm}
  33.  
  34. { TForm1 }
  35. constructor TProgressBar.Create(aOwner:TComponent);
  36. Begin
  37.   Inherited;
  38.   TheText := TStaticText.Create(Self);
  39.   TheText.Parent :=Self;
  40.   TheText.AutoSize := true;
  41. end;
  42.  
  43. procedure TForm1.FormCreate(Sender: TObject);
  44. begin
  45.   ProgressBar1.TheText.Font.Size := 16;
  46.   progressBar1.TheText.Caption := 'Try this way';
  47. end;
  48.  
  49. end.
  50.  
  51.  

The only true wisdom is knowing you know nothing

winni

  • Hero Member
  • *****
  • Posts: 3197
Re: ProgressBar
« Reply #13 on: October 30, 2021, 05:50:24 pm »
Hi!

If you use CodeTyphon you should ask in the CodeTyphon forum.

Winni

seghele0

  • Full Member
  • ***
  • Posts: 173
Re: ProgressBar
« Reply #14 on: October 31, 2021, 12:23:24 pm »
I use myapplications in both Lazarus and CT.
It's more instructive to use both.

This particular topic may be closed.
Thank you all.
 ;)

 

TinyPortal © 2005-2018