2022년 8월 18일 목요일

Delphi Seconds CountDown

흔히들 보는 3분 제한 같은 시간 카운트 다운 구현하다가 이번에 새로 알게된 함수

System.TTimeSpan 

샘플
=====================================================
var
  nCalculateTime: Word;
  oTimeSpan : TTimeSpan;
begin
  inherited;
  nCalculateTime := 0;
  Inc(FnCountTime);
  try
    if FnCountTime = DEFAULT_COUNTDOWN then begin
      pnl_CountDown.Caption := '남은시간 00:00';
      timer_Count.Enabled := False;
    end else begin
      oTimeSpan := TTimeSpan.FromTicks((TTimeSpan.TicksPerSecond * (DEFAULT_COUNTDOWN-FnCountTime)));
      pnl_CountDown.Caption := '남은시간 ' + Format('%.2d:%.2d', [oTimeSPan.Minutes, oTimespan.Seconds]);
    end;
  except
      on E:Exception do begin
      //
      end;
  end;

end;

간단하게 카운트 다운 시간으로 출력!