SRL Archive - Delphi/FPC Help and Tutorials

Change Button Caption Font


WhoCares357

2007-04-06 02:43:20

I'm trying to do this: if you press the button the font changes and stays that way until 30 minutes passes. I think I understand the time thing roughly, but could someone experienced give me an example of something like that?

PS Don't forget about the bold part ;).

Thanks to all that help.

Freddy1990

2007-04-06 04:53:38

uses: MMSystem

procedure TForm.ButtonClick(Sender: TObject);
var
Time: LongInt;
sFont: string;
const
Minutes = 30;
begin
with Button.Font do
begin
sFont := Font.Name;
Font.Name := 'Verdana';
Font.Style := [fsBold];
Time := TimeGetTime;
while (TimeGetTime - Time) <= (Minutes * 60000) do
Application.ProcessMessages;
Font.Name := sFont;
Font.Style := [];
end;
end;

WhoCares357

2007-04-06 13:02:33

From: Freddy1990
uses: MMSystem

procedure TForm.ButtonClick(Sender: TObject);
var
Time: LongInt;
sFont: string;
const
Minutes = 30;
begin
with Button.Font do
begin
sFont := Font.Name;
Font.Name := 'Verdana';
Font.Style := [fsBold];
Time := TimeGetTime;
while (TimeGetTime - Time) <= (Minutes * 60000) do
Application.ProcessMessages;
Font.Name := sFont;
Font.Style := [];
end;
end;



Wow, you're good. I was wondering if I could make the button unclickable instead of just bold? That would make it a little better. Thanks for the big help so far.

Freddy1990

2007-04-07 07:27:00

procedure TForm.ButtonClick(Sender: TObject);
var
Time: LongInt;
sFont: string;
const
Minutes = 30;
begin
with Button.Font do
begin
sFont := Font.Name;
Font.Name := 'Verdana';
Button.Enabled := False;
Time := TimeGetTime;
while (TimeGetTime - Time) <= (Minutes * 60000) do
Application.ProcessMessages;
Font.Name := sFont;
Button.Enabled := True;
end;
end;

WhoCares357

2007-04-07 11:49:53

Yup. Thanks Freddy. You are a good scripter :).

Freddy1990

2007-04-07 18:04:14

From: WhoCares357
Yup. Thanks Freddy. You are a good scripter :).


You code delphi, so coder ;)

WhoCares357

2007-04-08 06:05:04

Lol, alright, coder.

I tried rewriting your procedure a little to make it more of a timer, but now the button won't disable:
procedure TForm1.Button1Click(Sender: TObject);
var
i: Integer;
sFont: string;
const
Minutes = 15;
begin
with Button1.Font do
begin
sFont := Font.Name;
Font.Name := 'Verdana';
i := 0;
Button1.Enabled := False;
repeat
i := i + 1;
until(i >= Minutes * 60000);
Font.Name := sFont;
Button1.Enabled := True;
end;
end;


Also, what does Application.ProcessMessages do?

Freddy1990

2007-04-08 07:20:01

From: WhoCares357
Lol, alright, coder.

I tried rewriting your procedure a little to make it more of a timer, but now the button won't disable:
procedure TForm1.Button1Click(Sender: TObject);
var
i: Integer;
sFont: string;
const
Minutes = 15;
begin
with Button1.Font do
begin
sFont := Font.Name;
Font.Name := 'Verdana';
i := 0;
Button1.Enabled := False;
repeat
i := i + 1;
until(i >= Minutes * 60000);
Font.Name := sFont;
Button1.Enabled := True;
end;
end;


Also, what does Application.ProcessMessages do?

ProcessMessages is like DoEvents in VB, it's very much suggested you leave it like i coded iet, because now you will never get 60 minutes, ur not counting with miliseconds anymore because of the loop

WhoCares357

2007-04-08 10:42:49

From: Freddy1990
ProcessMessages is like DoEvents in VB, it's very much suggested you leave it like i coded iet, because now you will never get 60 minutes, ur not counting with miliseconds anymore because of the loop


Your function TimeGetTime was nonexistent in my (version?) of delphi. I tried the function Time, but (while Time - Start Time <= 30000 do) doesn't return the correct time left. It just freezes.

Freddy1990

2007-04-08 13:46:52

From: WhoCares357
Your function TimeGetTime was nonexistent in my (version?) of delphi. I tried the function Time, but (while Time - Start Time <= 30000 do) doesn't return the correct time left. It just freezes.


Why do you think i put "uses: MMSystem" in my post? To use the function you need to add MMSystem to ur uses list -_-

WhoCares357

2007-04-08 23:16:46

From: Freddy1990
Why do you think i put "uses: MMSystem" in my post? To use the function you need to add MMSystem to ur uses list -_-


Lol, sorry about that :p. I'll try it with the use now. Thanks.