Assuming that only one person is using the login ID zhe's been here for years doing a variety of stuff including databases etc., so this is unlikely to be homework.
Where I abbreviated as OP I meant Original Post, which to me looks like the tipical exercise, but even so, the task is so basic that I can't think of an even moderately experienced programmer failing to do it without help, hence my assumption (strenghtened by his previous recent posts) that the original poster is if not an absolute beginner at least not very experienced. At least with Pascal.
Of course, I might be wrong (and I am with distressing frequency lately); if so, my excuses to whoever might feel slighted, which was very far from my intention.
Here is the beloved recursive version. What a nonsense...
[... etc ...]
And here the "classical" one:
function factorial(const num: Int64): Int64;
{ Just an example: no range checks, inappropiate types, etc. }
begin
if num < 1 then
Result := 1
else
Result := num * factorial(num-1);
end;
Let's hope is not indeed homework; else we have just helped a student to cheat ...