Un programa básico para guiarse:
Label1 tiene la hora actual
Edit1 tiene la hora a restar
Label2 tiene horas, minutos y segundos resultantes
Código Delphi
[-]unit Unit1;
interface
uses
Winapi.Windows, System.SysUtils, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.StdCtrls, Vcl.ExtCtrls;
type
TForm1 = class(TForm)
Edit1: TEdit;
Button1: TButton;
Label1: TLabel;
Label2: TLabel;
Timer1: TTimer;
procedure Timer1Timer(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
public
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
dif: Extended;
begin
dif := Time() - StrToTime(Edit1.Text);
Label2.Caption := FormatDatetime('hh:nn:ss', dif);
if dif < 0 then
begin
Label2.Caption := '- ' + Label2.Caption;
end;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
Label1.Caption := TimeToStr(Time()) + ' menos ';
end;
end.
Código Delphi
[-]object Form1: TForm1
ClientHeight = 243
ClientWidth = 527
object Label1: TLabel
Left = 56
Top = 88
Width = 31
Height = 13
Caption = 'Label1'
end
object Label2: TLabel
Left = 384
Top = 88
Width = 31
Height = 13
Caption = 'Label2'
end
object Edit1: TEdit
Left = 144
Top = 85
Width = 121
Height = 21
TabOrder = 0
Text = '11:11:10'
end
object Button1: TButton
Left = 288
Top = 83
Width = 75
Height = 25
Caption = '='
TabOrder = 1
OnClick = Button1Click
end
object Timer1: TTimer
OnTimer = Timer1Timer
Left = 256
Top = 128
end
end
-