Recent

Author Topic: disobediant TLabel  (Read 8021 times)

Ron

  • Guest
disobediant TLabel
« on: May 22, 2004, 12:20:15 am »
I downloaded Lazarus-0.9.1.4-20040419-win32_binary.exe and installed it on my second HD (D:\). Drive D: does not contain Windows, however the package installed fine.

I compiled and ran a simple "Hello World" using the default Form1 and a TLabel component. This worked, but when I made the label wider and set the allignment to center, it didn't center. It didn't matter whether I set the component to TACenter, put it in the FormActivate runtime code or both. It still didn't center.

I couldn't find any optional fonts, fontsize, or font colors in the component. I guess they are not yet incorporated. I found that I could create the color and size at runtime, but could not change the character set. In fact I found the environment corrupts the Form1 source code when you try to change the TLabel font character set at runtime.

Anonymous

  • Guest
disobediant TLabel
« Reply #1 on: May 23, 2004, 06:30:33 am »
TStaticText seems to be a workable substitute for TLabel

Ron

  • Guest
disobediant TLabel
« Reply #2 on: May 23, 2004, 10:27:02 am »
Quote from: "Anonymous"
TStaticText seems to be a workable substitute for TLabel


I may have spoken too soon. There appear to be problems with the current beta on the Windows platform.
A simple task: Use a SpinEdit component to change the size of displayed text.
I placed a SpinEdit, a Label and a Static Text component on the default  form1. Here's the code I used to run it:

procedure TForm1.SpinEdit1Change(Sender: TObject);
begin
  { set limits }
  SpinEdit1.MinValue := 1;
  SpinEdit1.MaxValue := 100;
  SpinEdit1.Decimal_Places:=0;
  StaticText1.AutoSize:=true;
  Label1.AutoSize:=true;
  { Change font size }
  temp:=FloatToStr(SpinEdit1.Value); { temp declared global }
  StaticText1.Font.Size:=StrToInt(temp);
  Label1.Font.Size:=StrToInt(temp);
  { Compiles and runs, but doesn't work! so.. }
  with Label1 do
    Font.Size:=StrToInt(temp);
  with StaticText1 do
    Font.Size:=StrToInt(temp);
  { and this ^ compiles but blows up on execution }
end;

Ron

  • Guest
disobediant TLabel
« Reply #3 on: May 23, 2004, 10:38:38 am »
Oh, the { set limits } snippet is actually in Form1Activate and shown only for the limits used.

Quote from: "Ron"
Quote from: "Anonymous"
TStaticText seems to be a workable substitute for TLabel


I may have spoken too soon. There appear to be problems with the current beta on the Windows platform.
A simple task: Use a SpinEdit component to change the size of displayed text.
I placed a SpinEdit, a Label and a Static Text component on the default  form1. Here's the code I used to run it:

procedure TForm1.SpinEdit1Change(Sender: TObject);
begin
  { set limits }
  SpinEdit1.MinValue := 1;
  SpinEdit1.MaxValue := 100;
  SpinEdit1.Decimal_Places:=0;
  StaticText1.AutoSize:=true;
  Label1.AutoSize:=true;
  { Change font size }
  temp:=FloatToStr(SpinEdit1.Value); { temp declared global }
  StaticText1.Font.Size:=StrToInt(temp);
  Label1.Font.Size:=StrToInt(temp);
  { Compiles and runs, but doesn't work! so.. }
  with Label1 do
    Font.Size:=StrToInt(temp);
  with StaticText1 do
    Font.Size:=StrToInt(temp);
  { and this ^ compiles but blows up on execution }
end;

Ron

  • Guest
disobediant TLabel
« Reply #4 on: May 24, 2004, 09:24:44 am »
I discovered the reason the text wouldn't resize. There is a bug in the OnChange event handler for the SpinEdit component. The event exists in the component, but nothing happens when you call it.

Calling the SpinEdit OnChange procedure with a MouseDown event produces the desired effect. Unit1.pas (below).

unit unit1;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, StdCtrls,
  Spin;

type
  TForm1 = class(TForm)
    Label1: TLabel;
    SpinEdit1: TSpinEdit;
    StaticText1: TStaticText;
    procedure Form1Activate(Sender : TObject);
    procedure SpinEdit1Change(Sender : TObject);
    procedure SpinEdit1MouseDown(Sender: TOBject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);

  private
    { private declarations }
  public
    { public declarations }
  end;

var
  Form1: TForm1;
  temp : String;
implementation

{ TForm1 }

procedure TForm1.Form1Activate(Sender : TObject);
begin
  Label1.AutoSize:=true;
  StaticText1.AutoSize:=true;
  Label1.Font:=StaticText1.Font;
  SpinEdit1.Decimal_Places:=0;
  SpinEdit1.MaxValue:=100;
  SpinEdit1.MinValue:=1;
end;

procedure TForm1.SpinEdit1Change(Sender : TObject);
{ BUG! OnEvent handler asleep at the switch }
begin
  temp:=FloatToStr(SpinEdit1.Value);
  with StaticText1.Font do
    Size:=StrToInt(temp);
  Label1.Font:=StaticText1.Font; { need a font? Steal one! }
end;

{ the spare tire }
procedure TForm1.SpinEdit1MouseDown(Sender: TOBject; Button: TMouseButton;  Shift: TShiftState; X, Y: Integer);
begin
  SpinEdit1Change(Sender);
end;

initialization
  {$I unit1.lrs}

end.

Marc

  • Administrator
  • Hero Member
  • *
  • Posts: 2584
disobediant TLabel
« Reply #5 on: May 25, 2004, 12:39:06 pm »
2 things:
1) If you found a bug, please reprot it at our bugpage. Then it might get fixed.
2) Setting font properties is not possible at the moment due to theming issues. (read this as: on linux it is decided to let the theme handle the look and feel and therefore the code for setting fonts etc. is not complete yet)
//--
{$I stdsig.inc}
//-I still can't read someones mind
//-Bugs reported here will be forgotten. Use the bug tracker

Anonymous

  • Guest
disobediant TLabel
« Reply #6 on: May 25, 2004, 08:12:06 pm »
Quote from: "Marc"
2 things:
1) If you found a bug, please reprot it at our bugpage. Then it might get fixed.
2) Setting font properties is not possible at the moment due to theming issues. (read this as: on linux it is decided to let the theme handle the look and feel and therefore the code for setting fonts etc. is not complete yet)


Setting fonts is not the problem. The above code, with the MouseDown spare tire, will dynamically change the font of both TLabel and StaticText.
The problem is the SpinEdit OnChange event handler. It doesn't fire.

I don't feel comfortable reporting a bug until I am sure that it is one. Subsequent to encountering the problem, posting it here and then determining that it is indeed a bug, I have reported the bug to bug tracking.

 

TinyPortal © 2005-2018