Author Topic: Difference between defining a Function and Procedure and deciding the best one  (Read 849 times)

0 Members and 1 Guest are viewing this topic.

Offline frosty

  • Flagrunner
  • ****
  • Posts: 601
  • Uber Desert Eagle ^^
title says it all, basically when i try to use a procedure and call it, i get an error compared to using that as a function which with the same code but just Procedure changed to Function i get no error

so, whats the difference between Function MyFunc(); and Procedure MyFunc();

and whats the best situations to use procedures in place of functions?
« Last Edit: August 27, 2011, 03:26:27 am by frosty »
check out my server! click here

If at first you don't succeed, Improvise! :D

Offline tk

  • Soldier
  • **
  • Posts: 235
Procedure can only perform some action:

Code: (pascal) [Select]
procedure Display(x, y: integer);
begin
  WriteLn(IntToStr(x * y));
end;

// ...
Display(3, 4);
//...


Function is a procedure which may also return a result:

Code: (pascal) [Select]
function Multiply(x, y: integer): integer;
begin
  Result := x * y;
end;

// ...
WriteLn(IntToStr(Multiply(3, 4)));
// ...

Don't ask such basic questions btw, you can find such stuff in every available pascal/delphi tutorial.
« Last Edit: August 27, 2011, 03:16:41 am by tk »

Offline frosty

  • Flagrunner
  • ****
  • Posts: 601
  • Uber Desert Eagle ^^
tx tk, i wont do it again :D
check out my server! click here

If at first you don't succeed, Improvise! :D