LazBarcodes: Create qrcode in qrclock demo at runtime.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@8357 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2022-07-20 13:20:59 +00:00
parent 99bd06cca6
commit 8ecd374dba
3 changed files with 23 additions and 27 deletions

View File

@ -3,23 +3,9 @@ object MainForm: TMainForm
Height = 260 Height = 260
Top = 130 Top = 130
Width = 260 Width = 260
AutoSize = True
BorderStyle = bsDialog BorderStyle = bsDialog
Caption = 'QRClock' Caption = 'QRClock'
ClientHeight = 260
ClientWidth = 260
OnCreate = FormCreate OnCreate = FormCreate
object BarcodeQR: TBarcodeQR
Left = 0
Height = 260
Top = 0
Width = 260
ParentColor = False
Text = 'TBarcodeQR'
Scale = 12
AutoSize = True
RecommendedSymbolSize = False
end
object Timer: TTimer object Timer: TTimer
Interval = 250 Interval = 250
OnTimer = TimerTimer OnTimer = TimerTimer

View File

@ -12,11 +12,12 @@ type
{ TMainForm } { TMainForm }
TMainForm = class(TForm) TMainForm = class(TForm)
BarcodeQR: TBarcodeQR;
Timer: TTimer; Timer: TTimer;
procedure FormCreate(Sender: TObject); procedure FormCreate(Sender: TObject);
procedure TimerTimer(Sender: TObject); procedure TimerTimer(Sender: TObject);
private private
BarcodeQR: TBarcodeQR;
function GetNowText: String;
public public
@ -32,15 +33,9 @@ implementation
{ TMainForm } { TMainForm }
procedure TMainForm.TimerTimer(Sender: TObject); procedure TMainForm.TimerTimer(Sender: TObject);
var
dt: TDateTime;
sd, st: String;
begin begin
dt := Now(); BarcodeQR.Text := GetNowText;
sd := FormatDateTime('dddddd', dt); Caption := 'QRClock: ' + StringReplace(BarcodeQR.Text, LineEnding, ' - ', []);
st := FormatDateTime('hh:nn:ss', dt);
Caption := 'QRClock: ' + sd + ' - ' + st;
BarcodeQR.Text := sd + LineEnding + st;
end; end;
procedure TMainForm.FormCreate(Sender: TObject); procedure TMainForm.FormCreate(Sender: TObject);
@ -48,11 +43,25 @@ var
w: Integer = 0; w: Integer = 0;
h: Integer = 0; h: Integer = 0;
begin begin
// Avoid switching to final form size while form is already visible BarcodeQR := TBarcodeQR.Create(self);
TimerTimer(nil); BarcodeQR.Parent := self;
BarcodeQR.Scale := 16;
BarcodeQR.Text := GetNowText;
BarcodeQR.GetPreferredSize(w, h); BarcodeQR.GetPreferredSize(w, h);
Width := w; BarcodeQR.SetBounds(0, 0, w, h);
Height := h; ClientWidth := w;
ClientHeight := h;
end;
function TMainForm.GetNowText: String;
var
dt: TDateTime;
sd, st: String;
begin
dt := Now();
sd := FormatDateTime('dddddd', dt);
st := FormatDateTime('hh:nn:ss', dt);
Result := sd + LineEnding + st;
end; end;
end. end.

View File

@ -44,6 +44,7 @@
<Filename Value="main.pas"/> <Filename Value="main.pas"/>
<IsPartOfProject Value="True"/> <IsPartOfProject Value="True"/>
<ComponentName Value="MainForm"/> <ComponentName Value="MainForm"/>
<HasResources Value="True"/>
<ResourceBaseClass Value="Form"/> <ResourceBaseClass Value="Form"/>
</Unit1> </Unit1>
</Units> </Units>