1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Donation with Paypal!!!

    Go to your paypal account and send directly donation to [email protected]

    1 month - 10 $ - Standart VIP

    6 months - 20 $- Standart VIP

    1 year - 30 $- Standart VIP

    2 years - 50 $- Standart VIP

    Gold member for life - 150 $- Standart VIP

    High Vip (Standart VIP include) group please send PM or email to [email protected] for info

    After Donation please send email to [email protected]

  3. Donation Ways 2020


    Paysend
  4. Telegram

  5. Delphifan Magazine
Dismiss Notice

Donation with Paypal!!!

Go to your paypal account and send directly donation to [email protected]

1 month - 10 $ - Standart VIP

6 months - 20 $- Standart VIP

1 year - 30 $- Standart VIP

2 years - 50 $- Standart VIP

Gold member for life - 150 $- Standart VIP

High Vip (Standart VIP include) group please send PM or email to [email protected] for info

After Donation please send email to [email protected]

Dismiss Notice
For open hidden message no need write thanks, thank etc. Enough is click to like button on right side of thread.

Complete date in TField

Discussion in 'Delphi Programming' started by medreis, Nov 9, 2015.

  1. medreis
    Offline

    medreis DF Junior

    Procedure CompletaDataField( Const pData : String ; pField : TFIELD ; const pErro : boolean = True );
    var
      DataStr          : String;
      Year, Month, Day : Word;
      i, TotSepara     : Integer;
    begin

      DataStr:= pData;

      if DataStr = '' then
      begin
        pField.Value := NULL;
        Exit;
      end;
      TotSepara := 0;
      //Conta quantos numeros existem na Variaval DataStr( pData )
      for i := 1 to Length(DataStr) do
      begin
        if not (DataStr in ['0'..'9']) then
        begin
          DataStr := FormatSettings.DateSeparator;
          inc(TotSepara);
        end;
      end;
      // Remove os Separadores de Data
      while (DataStr <> '') and ( DataStr[Length(DataStr)] = FormatSettings.DateSeparator) do
      begin
        Delete(DataStr, Length(DataStr), 1);
        Dec(TotSepara);
      end;
      // Pega o Ano mes e Dia
      DecodeDate(Now, Year, Month, Day);
      if TotSepara = 0 then
      begin
        case Length(DataStr) of
             0 : DataStr := DateToStr(date);
          1, 2 : DataStr := DataStr+FormatSettings.DateSeparator+IntToStr(Month);
             4 : Insert(FormatSettings.DateSeparator, DataStr, 3);
          6, 8 : begin
                   Insert(FormatSettings.DateSeparator, DataStr, 5);
                   Insert(FormatSettings.DateSeparator, DataStr, 3);
                 end;
        end;
      end;
      try
        pField.Value := StrToDate(DataStr);
      except
        if pErro = true then
          pField.Value := Date
        else
         pField.Value := NULL;
      end;
    end;


    //How to use

    //Use this in OnSetText event the Field

    procedure TFmBI0004.qry_vendedor_admissaoSetText(Sender: TField;  const Text: string);
    begin
      inherited;
      //The function complete the date
      CompletaDataField(Text,Sender);
    end;
     
     

Share This Page