Forum > Beginners

Procedure declaration before implementation section

(1/4) > >>

pascal111:
Is it correct to put a procedure declaration before implementation section and why is it acceptable to ignore procedure declaration and just work with its copy that's within implementation section?

Compiler accepted next code:


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---unit Unit1; {$mode objfpc}{$H+} interface uses  Classes, SysUtils, Forms, Controls, Graphics, Dialogs; type   { TForm1 }   TForm1 = class(TForm)    procedure FormCreate(Sender: TObject);  private   public   end; var  Form1: TForm1;  //procedure x_proc; implementation {$R *.lfm} { TForm1 } procedure TForm1.FormCreate(Sender: TObject);begin end;  procedure x_proc;begin end;   end.  

Thausand:

--- Quote from: pascal111 on June 27, 2022, 11:59:24 pm ---Is it correct to put a procedure declaration before implementation section

--- End quote ---
yes.


--- Quote ---.. and why is it acceptable to ignore procedure declaration and just work with its copy that's within implementation section?

--- End quote ---
It just "private" function to unit implementation.

More read here https://wiki.freepascal.org/Interface and here https://www.freepascal.org/docs-html/ref/refse112.html#x233-25700016.2

PascalDragon:

--- Quote from: pascal111 on June 27, 2022, 11:59:24 pm ---Is it correct to put a procedure declaration before implementation section and why is it acceptable to ignore procedure declaration and just work with its copy that's within implementation section?
--- End quote ---

You only need to declare a function or procedure in the interface-section (which is the section before the implementation-section) if you want the routine to be accessible from another unit.

Zvoni:

--- Quote from: PascalDragon on June 28, 2022, 01:43:03 pm ---
--- Quote from: pascal111 on June 27, 2022, 11:59:24 pm ---Is it correct to put a procedure declaration before implementation section and why is it acceptable to ignore procedure declaration and just work with its copy that's within implementation section?
--- End quote ---

You only need to declare a function or procedure in the interface-section (which is the section before the implementation-section) if you want the routine to be accessible from another unit.

--- End quote ---
.... or if you need a forward-declaration (for whatever reason) within the same unit?

pascal111:
Thanks for you all guys!
I think I got it.

Navigation

[0] Message Index

[#] Next page

Go to full version