Forum > Beginners

Procedure declaration before implementation section

<< < (3/4) > >>

Thaddy:
If you specialize in the interface section, the implementation part works OK.

PascalDragon:

--- Quote from: Zvoni on June 28, 2022, 02:17:26 pm ---
--- 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?

--- End quote ---

Then you use a forward-declaration instead of making it public for all users of the unit.


--- Quote from: Thaddy on June 29, 2022, 01:03:39 pm ---If you specialize in the interface section, the implementation part works OK.

--- End quote ---

You can't specialize a generic routine in the interface-section.

Thaddy:
Of course you can, Sarah:
--- 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 naamloosunit;{$mode delphi}interfacetype   TspecializeMe = TArray<Integer>; // specializedimplementationend.

PascalDragon:

--- Quote from: Thaddy on June 29, 2022, 02:23:41 pm ---Of course you can, Sarah:
--- 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 naamloosunit;{$mode delphi}interfacetype   TspecializeMe = TArray<Integer>; // specializedimplementationend.
--- End quote ---

Learn to read (emphasis mine):


--- Quote from: PascalDragon on June 29, 2022, 01:41:24 pm ---You can't specialize a generic ROUTINE in the interface-section.

--- End quote ---

Warfley's example was about a generic routine, and not a generic type.

pascal111:
Ok guys!
It seems I have a problem, I was testing implementing a function within the implementation section without declaring it in interface section and I met an error as it's shown in the image.

This device has Windows 11.

The code is this one:


--- 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; implementation {$R *.lfm} { TForm1 } procedure TForm1.FormCreate(Sender: TObject);begin end; foo():int;begin result:=888;end; end.  

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version