Title: TTime-Int, TDate-Int
Question: How can i Save A TDate or TTime types (or date of TDateTime or Time of TDateTime) variables in a Integer to use it in other areas?
Answer:
first you should to use the Controls and DateUtils unit.
uses Controls, DateUtils;
....
function DateToInt(ADate: TDate): Integer;
function IntToDate(ADate: Integer): TDate;
function TimeToInt(ATime: TTime): Integer;
function IntToTime(ATime: Integer):TTime;
function DateToInt(ADate: TDate): Integer;
var
D,M,Y: Word;
begin
Result := 0;
DecodeDate(ADate, Y,M, D);
Result := D;
Result := Result or (M shl 5);
Result := Result or (Y shl 9);
end;
function IntToDate(ADate: Integer): TDate;
var
D,M,Y: integer;
begin
D:= ADate and $1F;
M:= (ADate shr 5) and $F;
Y:= ADate shr 9;
Result := EncodeDate(Y, M, D);
end;
function TimeToInt(ATime: TTime): Integer;
var
H, M, S, MS: Word;
begin
Result := 0;
DecodeTime(ATime, H, M, S, MS);
Result := H;
Result := Result or (M shl 5);
Result := Result or (S shl 11);
Result := Result or (MS shl 17);
end;
function IntToTime(ATime: Integer):TTime;
var
H, M, S, MS: Word;
begin
H := ATime and $1F;
M := (ATime shr 5) and $3F;
S := (ATime shr 11) and $3F;
MS := ATime shr 17;
Result := EncodeTime(H, M, S, MS);
end;