[Delphi] Changing a label caption with a button

Discuss about Programming here. You may release your source, post guide and even ask questions!

Moderator: wizme

Post Reply
Boredness
The Emperor
The Emperor
Posts: 2539
Joined: Wed Aug 26, 2009 9:50 pm
Location: Singapore
Contact:

[Delphi] Changing a label caption with a button

Post by Boredness »

Today, I'm gonna teach you how to change a label caption with a click of a button

1)Run Delphi
2)Put a label and a button to your form. (They're both under "Standerd" tab)
3)Change the label caption to "hello" (You may change to anything you want actually) at the Object Inspector.
4)Double click on the button and you should see the code.

Code: Select all

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs;

type
  TForm1 = class(TForm)
    Label1: TLabel;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin

end;

end.
5)Under

Code: Select all

procedure TForm1.Button1Click(Sender: TObject);
begin
6)Compile you project by pressing F9.
7)Then, the exe should pop up, Click the button and then the 'hello' will become 'bye'.

This should be your final code

Code: Select all

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Label1: TLabel;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
label1.Caption := 'Bye'
end;

end.
Donate money to my paypal account @ danielongdequan1996@hotmail.com to keep this website alive!
bluefirzen
Holy Philosopher
Holy Philosopher
Posts: 904
Joined: Sun Aug 30, 2009 9:01 pm
Location: Somewhere surrounded by Japan Girls
Contact:

Re: [Delphi] Changing a label caption with a button

Post by bluefirzen »

Thanks bro {: .
btw online msn soon.
i got some questions i wish to ask about this O_O LOL
Image
Boredness
The Emperor
The Emperor
Posts: 2539
Joined: Wed Aug 26, 2009 9:50 pm
Location: Singapore
Contact:

Re: [Delphi] Changing a label caption with a button

Post by Boredness »

bluefirzen wrote:Thanks bro {: .
btw online msn soon.
i got some questions i wish to ask about this O_O LOL
Post your questions here, i'm quite busy today
Donate money to my paypal account @ danielongdequan1996@hotmail.com to keep this website alive!
Post Reply