Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2009-12

Dynamic creation of TTrackBar

13 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Brad Campbell

G'day all,

I'm currently using "Lazarus 0.9.29 r22679 FPC 2.2.5 i386-linux-gtk 2 (beta)".

On a form, I'm creating 30-40 instances of a TTrackBar dynamically. If, at design time I have a TTrackBar on the form, this all goes swimingly. If, however there is no TTrackBar on the form, when I run the application I get "Class "TTrackBar" not found.".

I'm pretty sure I've created components dynamically before and not bumped up against this. I *know* I'm doing something dumb, but it's late and I just can't figure out what it is.

Can someone whack me with the clue bat please?

Regards,
Brad

Dolphins are so intelligent that within a few weeks they can train Americans to stand at the edge of the pool and throw them fish.

Reply by email

Mattias Gaertner
to Brad Campbell
Show quoted text 7 lines
G'day all, I'm currently using "Lazarus 0.9.29 r22679 FPC 2.2.5 i386-linux-gtk 2 (beta)". On a form, I'm creating 30-40 instances of a TTrackBar dynamically. If, at design time I have a TTrackBar on the form, this all goes swimingly. If, however there is no TTrackBar on the form, when I run the application I get "Class "TTrackBar" not found.".

How do you create the TTrackBars?

I'm pretty sure I've created components dynamically before and not bumped up against this. I *know* I'm doing something dumb, but it's late and I just can't figure out what it is. Can someone whack me with the clue bat please?

Mattias

Reply by email

Duncan Parsons
to Brad Campbell: I'm currently using "Lazarus 0.9.29 r22679 FPC 2.2.5 i386-linux-gtk 2 (beta)". On a form,…

Not got Laz/fpc code near me, but my guess is that when you have a TTrackBar on the form, the unit that it's housed in will be added to the uses list, and if you delete it (provided no other referenced classes are included) it may get removed.

Find which unit TTrackBar is declared in and add it to the relevant uses clause by hand..

Does that help?

DSP

Earlier message 29 lines
-----Original Message----- From: Brad Campbell [mailto:] Sent: 17 December 2009 15:37 To: General mailing list Subject: [Lazarus] Dynamic creation of TTrackBar G'day all, I'm currently using "Lazarus 0.9.29 r22679 FPC 2.2.5 i386-linux-gtk 2 (beta)". On a form, I'm creating 30-40 instances of a TTrackBar dynamically. If, at design time I have a TTrackBar on the form, this all goes swimingly. If, however there is no TTrackBar on the form, when I run the application I get "Class "TTrackBar" not found.". I'm pretty sure I've created components dynamically before and not bumped up against this. I *know* I'm doing something dumb, but it's late and I just can't figure out what it is. Can someone whack me with the clue bat please? Regards, Brad -- Dolphins are so intelligent that within a few weeks they can train Americans to stand at the edge of the pool and throw them fish. --

Reply by email

Brad Campbell
to Mattias Gaertner: On Thu, 17 Dec 2009 23:37:21 +0800 How do you create the TTrackBars? Mattias
Mattias Gaertner wrote 13 lines
On Thu, 17 Dec 2009 23:37:21 +0800 Brad Campbell wrote: > G'day all, > > I'm currently using "Lazarus 0.9.29 r22679 FPC 2.2.5 i386-linux-gtk 2 (beta)". > > On a form, I'm creating 30-40 instances of a TTrackBar dynamically. If, at design time I have a > TTrackBar on the form, this all goes swimingly. If, however there is no TTrackBar on the form, when > I run the application I get "Class "TTrackBar" not found.". How do you create the TTrackBars?

Sorry about that.

Var
	Fred : Array[0..15] of TTrackBar;
Procedure Doit;
Var
   I : Integer;
Begin
   For I := 0 to 15 do
     Begin
     Fred[I] := TTrackBar.Create(Form1);
     Fred[I].Parent := Form1;
     End;
End;
Dolphins are so intelligent that within a few weeks they can train Americans to stand at the edge of the pool and throw them fish.

Reply by email

Mattias Gaertner
to Brad Campbell
Show quoted text 30 lines
Mattias Gaertner wrote: > On Thu, 17 Dec 2009 23:37:21 +0800 > Brad Campbell wrote: > >> G'day all, >> >> I'm currently using "Lazarus 0.9.29 r22679 FPC 2.2.5 i386-linux-gtk 2 (beta)". >> >> On a form, I'm creating 30-40 instances of a TTrackBar dynamically. If, at design time I have a >> TTrackBar on the form, this all goes swimingly. If, however there is no TTrackBar on the form, when >> I run the application I get "Class "TTrackBar" not found.". > > How do you create the TTrackBars? > Sorry about that. Var Fred : Array[0..15] of TTrackBar; Procedure Doit; Var I : Integer; Begin For I := 0 to 15 do Begin Fred[I] := TTrackBar.Create(Form1); Fred[I].Parent := Form1; End; End;

Add unit comctrls to uses clauses.

Mattias

Reply by email

Brad Campbell
to Duncan Parsons: Not got Laz/fpc code near me, but my guess is that when you have a TTrackBar on the form,…
Duncan Parsons wrote 9 lines
Not got Laz/fpc code near me, but my guess is that when you have a TTrackBar on the form, the unit that it's housed in will be added to the uses list, and if you delete it (provided no other referenced classes are included) it may get removed. Find which unit TTrackBar is declared in and add it to the relevant uses clause by hand.. Does that help?

No, not really. I had already thought along the same lines and checked it out.

I would have thought that given I'm referencing TTrackBar in the array definition it would grumble if the unit was not in the uses clause anyway.

Thanks for the thought tho. I've certainly been caught by errors like this in the past.

For reference, here is the complete procedure.
The form var section has this :

Var
   TapSliders : Array[0..15] of TTrackBar;
   TapLabels : Array[0..15] of TLabel;

This is where I create some of the sliders.

Any suggestions on how I can de-crapify this process is most welcome too :) I'm creating an array of sliders at run time which are all aligned against each other on a panel in 2 rows. I've fixed the numbers for testing purposes, but it has / will been / be dynamic depending on the hardware it is talking to.

procedure TForm1.FormCreate(Sender: TObject);
Var
         I : Integer;
begin
   Ser := TBlockSerial.Create;
   For I := 0 to 15 do
       Begin
       TapLabels[I] := TLabel.Create(Panel2);
       TapLabels[I].Layout := tlCenter;
       TapLabels[I].Alignment := taCenter;
       TapLabels[I].Parent := Panel2;
       TapLabels[I].Caption := 'L'+IntToStr(I);
       TapLabels[I].Anchors := [];
       End;
   For I := 0 to 15 do
       Begin
       TapSliders[I] := TTrackBar.Create(Panel2);
       TapSliders[I].Top := 1;
       TapSliders[I].Max := 32768;
       TapSliders[I].Position:= I*50;
       TapSliders[I].Name := 'TapSliders'+IntToStr(I);
       TapSliders[I].Parent := Panel2;
       TapSliders[I].Orientation := trVertical;
       TapSliders[I].TickStyle := tsNone;
       TapSliders[I].OnChange:= @TrackBar1Change;
       TapSliders[I].Tag := I+$ABCD;
       TapSliders[I].BorderSpacing.Left := 10;
       TapSliders[I].Width := TapSliders[I].Width + 5;
       End;
       For I := 0 to 7 do
           Begin
           TapSliders[I].AnchorSide[akTop].Control := Panel2;
           TapSliders[I].AnchorSide[akTop].Side := asrTop;
           TapSliders[I].Height := (Panel2.Height Div 2) - 5 - TapLabels[0].Height;
           TapLabels[I].AnchorSide[akTop].Control := TapSliders[I];
           TapLabels[I].AnchorSide[akTop].Side := asrBottom;
           TapLabels[I].AnchorSide[akLeft].Control := TapSliders[I];
           TapLabels[I].AnchorSide[akLeft].Side := asrLeft;
           TapLabels[I].AnchorSide[akRight].Control := TapSliders[I];
           TapLabels[I].AnchorSide[akRight].Side := asrRight;
           TapLabels[I].Anchors := TapLabels[I].Anchors+[akTop,akLeft,akRight];
           End;
       For I := 8 to 15 do
           Begin
           TapSliders[I].AnchorSide[akTop].Control := TapLabels[I-8];
           TapSliders[I].AnchorSide[akTop].Side := asrBottom;
           TapSliders[I].AnchorSide[akBottom].Control := TapLabels[I];
           TapSliders[I].AnchorSide[akBottom].Side := asrtop;
           TapSliders[I].Anchors := TapSliders[I].Anchors+[akBottom];
           TapLabels[I].AnchorSide[akBottom].Control := Panel2;
           TapLabels[I].AnchorSide[akBottom].Side := asrBottom;
           TapLabels[I].AnchorSide[akLeft].Control := TapSliders[I];
           TapLabels[I].AnchorSide[akLeft].Side := asrLeft;
           TapLabels[I].AnchorSide[akRight].Control := TapSliders[I];
           TapLabels[I].AnchorSide[akRight].Side := asrRight;
           TapLabels[I].Anchors := TapLabels[I].Anchors+[akBottom,akLeft,akRight];
           End;
       TapSliders[0].AnchorSide[akLeft].Control := Panel2;
       TapSliders[0].AnchorSide[akLeft].Side := asrLeft;
       TapSliders[8].AnchorSide[akLeft].Control := Panel2;
       TapSliders[8].AnchorSide[akLeft].Side := asrLeft;
       For I := 1 to 7 do
           Begin
           TapSliders[I].AnchorSide[akLeft].Control := TapSliders[I-1];
           TapSliders[I+8].AnchorSide[akLeft].Control := TapSliders[I-1+8];
           TapSliders[I].AnchorSide[akLeft].Side := asrRight;
           TapSliders[I+8].AnchorSide[akLeft].Side := asrRight;
           End;
       For I := 0 to 15 do
           TapSliders[I].Anchors := TapSliders[I].Anchors+[akTop,akLeft];
end;

Regards,
Brad

Dolphins are so intelligent that within a few weeks they can train Americans to stand at the edge of the pool and throw them fish.

Reply by email

Brad Campbell
to Mattias Gaertner: On Thu, 17 Dec 2009 23:58:59 +0800 Add unit comctrls to uses clauses. Mattias
Mattias Gaertner wrote
Add unit comctrls to uses clauses.

uses
Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs, Menus, StdCtrls, ExtCtrls, ComCtrls, UnixSerial, BaseUnix, PortScan,

   DateUtils, Math;

Regards,
Brad

Dolphins are so intelligent that within a few weeks they can train Americans to stand at the edge of the pool and throw them fish.

Reply by email

Brad Campbell
to Brad Campbell
Brad Campbell wrote 9 lines
Mattias Gaertner wrote: > > Add unit comctrls to uses clauses. > uses Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs, Menus, StdCtrls, ExtCtrls, ComCtrls, UnixSerial, BaseUnix, PortScan, DateUtils, Math;

Just to check I removed ComCtrls and of course it failed to compile. With it in, it just dies at run time.

Dolphins are so intelligent that within a few weeks they can train Americans to stand at the edge of the pool and throw them fish.

Reply by email

Brad Campbell
to Brad Campbell
Brad Campbell wrote 15 lines
Brad Campbell wrote: > Mattias Gaertner wrote: >> >> Add unit comctrls to uses clauses. >> > uses > Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, > Dialogs, > Menus, StdCtrls, ExtCtrls, ComCtrls, UnixSerial, BaseUnix, PortScan, > DateUtils, Math; Just to check I removed ComCtrls and of course it failed to compile. With it in, it just dies at run time.

Ok, nevermind. The fault lies elsewhere.
When I remove the component from the form, it's not recompiling the lrs file. If I manually create the .lrs file from the .lfm file before I compile the problem goes away.

Now I just need to figure out what I've damaged that is stopping lazarus recompiling the lrs file when I change the form.

Sorry for the noise.

Regards,
Brad

Dolphins are so intelligent that within a few weeks they can train Americans to stand at the edge of the pool and throw them fish.

Reply by email

Mattias Gaertner
to Brad Campbell: Sorry about that. Var Fred : Array[0..15] of TTrackBar; Procedure Doit; Var I : Integer;…
Show quoted text 11 lines
Mattias Gaertner wrote: > On Thu, 17 Dec 2009 23:37:21 +0800 > Brad Campbell wrote: > >> G'day all, >> >> I'm currently using "Lazarus 0.9.29 r22679 FPC 2.2.5 i386-linux-gtk 2 (beta)". >> >> On a form, I'm creating 30-40 instances of a TTrackBar dynamically. If, at design time I have a >> TTrackBar on the form, this all goes swimingly. If, however there is no TTrackBar on the form, when >> I run the application I get "Class "TTrackBar" not found.".

You get this only at run time?

Check if your lfm file contains a trackbar.
Maybe you deleted it in the published section of the form, but not on the form itself.

Mattias

Reply by email

Mattias Gaertner
to Brad Campbell: Ok, nevermind. The fault lies elsewhere. When I remove the component from the form, it's…
Show quoted text 6 lines
[...] When I remove the component from the form, it's not recompiling the lrs file. If I manually create the .lrs file from the .lfm file before I compile the problem goes away. Now I just need to figure out what I've damaged that is stopping lazarus recompiling the lrs file when I change the form.

The lrs file is updated
1. when saving the lfm
2. before compiling the project and the lfm file is newer than the lrs file and the unit is listed in the project inspector.

Mattias

Reply by email

Brad Campbell
to Mattias Gaertner
Mattias Gaertner wrote 14 lines
On Fri, 18 Dec 2009 00:28:03 +0800 Brad Campbell wrote: > [...] > When I remove the component from the form, it's not recompiling the lrs file. > If I manually create the .lrs file from the .lfm file before I compile the problem goes away. > > Now I just need to figure out what I've damaged that is stopping lazarus recompiling the lrs file > when I change the form. The lrs file is updated 1. when saving the lfm 2. before compiling the project and the lfm file is newer than the lrs file and the unit is listed in the project inspector.

For whatever reason (and it was not permissions) lazarus was not updating the I updated it manually it worked though. I deleted the lrs, and let lazarus recreate it, and now it's all happy. I'll chalk it up to an oddity. I've certainly not seen it before!

Regards,

Dolphins are so intelligent that within a few weeks they can train Americans to stand at the edge of the pool and throw them fish.

Reply by email

Brad Campbell
to Brad Campbell
Brad Campbell wrote 24 lines
Mattias Gaertner wrote: > On Fri, 18 Dec 2009 00:28:03 +0800 > Brad Campbell wrote: > >> [...] >> When I remove the component from the form, it's not recompiling the >> lrs file. >> If I manually create the .lrs file from the .lfm file before I >> compile the problem goes away. >> >> Now I just need to figure out what I've damaged that is stopping >> lazarus recompiling the lrs file when I change the form. > > The lrs file is updated > 1. when saving the lfm > 2. before compiling the project and the lfm file is newer than the lrs > file and the unit is listed in the project inspector. For whatever reason (and it was not permissions) lazarus was not updating the I updated it manually it worked though. I deleted the lrs, and let lazarus recreate it, and now it's all happy. I'll chalk it up to an oddity. I've certainly not seen it before! Regards,

Ok, now I see. There was an existing .lrs file in the project directory.

When lazarus creates one it is placed in "lib/i386-linux/". The file in the project directory takes precedence and is not being automatically updated. When I removed the file in the project directory it all started to behave normally. How peculiar.

Regards,

Dolphins are so intelligent that within a few weeks they can train Americans to stand at the edge of the pool and throw them fish.

Reply by email