0

I was trying to change the color of my label. The code does not show any error, but it does not seem to work either.

unit Unit1;

{$mode objfpc}{$H+}

interface

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

type
  { TForm1 }

  TForm1 = class(TForm)

    Label1: TLabel;
    procedure FormCreate(Sender:Tobject);

  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

  {TAmpel}
  TAmpel = class
  private
    FAmpel1: string;
  public
    constructor Create;
    procedure schalten();
  end;

var
  Form1: TForm1;

implementation

{$R *.lfm}

constructor TAmpel.Create;
begin
  FAmpel1 := 'TAmpel1';
end;

procedure TAmpel.schalten();
begin
end;
procedure TForm1.FormCreate(Sender: TObject);
begin

  Label1.Font.Color := clRed;
end;


end.

I tried

Label1.StyleElements := Label1.StyleElements; 

but that did not work for me.

It would be nice if somebody could help me... I'm new to lazarus and my teacher does not explain anything

5
  • 1
    What do you expecting doing Label1.StyleElements := Label1.StyleElements? You're re-assigning the value that's already in there. If you're new to programming then consider reading a book/tutorial. And stop tagging questions with Delphi when they have nothing to do with it.
    – AmigoJack
    Sep 25 at 20:14
  • Changed it. And the StyleElement Thing i found on Stackoverflow. It worked for the guy Sep 25 at 20:57
  • Welcome to the internet - it works through links. Please link to the answer or comment where you found that - I'm very sure you misinterpreted/misread what you've found.
    – AmigoJack
    Sep 25 at 21:33
  • Unfortunately, the code you've written doesn't seem to make much sense. Have you considered finding a good book or online tutorial to learn the basics?
    – Ken White
    Sep 25 at 23:12
  • 1
    The original code Label1.Font.Color := clRed; in the form constructor works perfectly ok. What made you think it doesn't work? Did you see the text of the label in some other color than red? Or did you not see any text? If the latter case, perhaps you cleared Label1.Caption and forgot to assign a new text? We can't tell as you don't explain any details of the problem. Sep 26 at 9:38

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.