I put those in the main Var.
decode_date(myReadWord(Header.Date));
You treat decode_date as a procedure here. You don't do anything with the result of that function. In the olden days of Turbo Pascal the line you have now wasn't even possible because you don't assign the decode_date() result to anything. Below is an example line how to use it.
--------
Oef...

The others are right... at this moment you lack some basic programming knowledge in Pascal. That's nothing to be ashamed of, everyone needs to learn at some point, but it does mean we need to go back to the basics. So I apologize to the others for going really basic in this post. (I'm not a teacher so I hope I can explain this clearly.)
First... you've been given a perfectly good function by shobits1 where you (like molly already pointed out)
stripped out the local variable. Why?
(Do you know the difference between local and global variables??) You only need those variable year, day etc. in that procedure so keep them there. Don't make them global because it will only confuse you.
function decode_date( sdate:word): TDateTime;
var
year : integer;
day, month, y_offset: byte;
begin
y_offset := (sdate AND %1111111000000000) shr 9;
month := (sdate AND %0000000111100000) shr 5;
day := (sdate AND %0000000000011111);
if y_offset < 100 then
year := 2000 + y_offset
else
year := 1999 - y_offset + 100;
result := EncodeDate(year, month, day);
end;
When I do the following it works perfectly so don't mess with it. Try to understand the function before you change it.
Writeln('Fecha Modificacion: ', datetostr(decode_date(Header.Date)));
Next your encode-procedure:
function encode_date( stdate :TDateTime ) : word;
begin
y_offset := (stdate OR %0000000001111111) shl 9;
month := (stdate OR %0000000000001111) shl 5;
day := (stdate OR %0000000000011111);
if y_offset > 100 then
year := 2000 - y_offset
else
year := 1999 + y_offset - 100;
result := DecodeDate(stdate,year,month,day);
end;
I have 2 major problems (besides some little ones) with that one.
First one is this
y_offset := (stdate OR %0000000001111111) shl 9;
You think it's the opposite of this:
y_offset := (sdate AND %1111111000000000) shr 9;
Lets create another example (bear with me):
X := (Y + 5) / 5
Now I want the reverse. I mean by that... I want you to do "
Y := something".
(note: please pay attention to the brackets. Do you remember the order in which everything is calculated?)
Can you give me the correct line???
So in this line
y_offset := (stdate OR %0000000001111111) shl 9;
I
don't want to calculate y_offset, but I want to calculate
stdate FROM y_offset.
Can you give me the correct line???
Next problem is that I've already given you 3 times the way you need to build the encode_date() function. Begin at the end of decode_date() and
do those instruction at the beginning of encode_date().
Let's look at another simple example:
function foo(Xin: word): Word;
var
helper: Word;
begin
helper := Xin + 5;
helper := helper / 5
Result := helper;
end;
How would you "reverse this procedure" ?????
I want this to work:
Q := foo(5);
Z := foo_reversed(Q);
writeln('Z should be 5');
How would your foo_reversed look like?? With what instruction would you begin that function and what instruction second?
Maybe if I give you a description of what encode_date() needs to do it will become clear:
encode_date()
gets a stdate parameter which is a TDateTime in Object Pascal format (i.e. double). You want the result of the function to be a WORD with specification as given (with bits). So you
first need to
extract the year, month and day from the stdate (that should be your FIRST lines in the function, i.e. decodeDate). Then you need to
calculate y_offset which you're going to use in your bitwise-operations. AFTER that you need to
do the bitwise operation. Starting with stdate as 0 and adding the result of those 3 bitwiseoperations to it.
I hope that with that description you can create a new encode_date() which will work better.
Edit: Before you get to the bitwise-operations in your encode_date() function I'll give you another big hint. OR is not the opposite of AND. Look again at the wiki. The opposite of AND is
XOR. But it might be better to
clear your head when you come to those instructions because you don't even need AND or XOR for encode_date(). Just the shl's are sufficient. Because if you shift bits to the left the bits which appear at the right are already 0. But you'll see when you get there.