Forum > Beginners

Declaring procedure in Unit as private

(1/2) > >>

Bill52:
Could someone please give an example how to declare a procedure in a Unit as private? I can't find this in the FreePascal reference guide.

Many thanks,

Bill

typo:
If you want that a procedure be private of a unit, you can simply not declare it.

howardpc:
Perhaps you mean 'hiding' a procedure in the implementation section?


--- Code: ---unit Unit1;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils;

// normal interface type declarations etc.

implementation

procedure UnseenOutsideThisUnit;
begin
  ...
end;

end.

--- End code ---

taazz:
In order to make anything private in a unit you declare it in the implementation section as forward and not in the interface.
eg
--- Code: ---implementation

procedure DoYourThing;forward;

procedure WhatYouWant;
begin
  DoyourThing;
end;

procedure DoYourThing;
begin
  WriteLn('Done');
end;

--- End code ---

Bart:

--- Quote from: taazz on August 21, 2014, 04:11:17 pm ---In order to make anything private in a unit you declare it in the implementation section as forward and not in the interface.
eg

--- End quote ---

The forward declaration is not needed to"hide" the function:


--- Code: ---unit example;

interface

procedure WhatYouWant;

implementation

procedure DoYourThing;
begin
  WriteLn('Done');
end;

procedure WhatYouWant;
begin
  DoyourThing;
end;

--- End code ---

procedure WhatYouWant is visible to anything that has example in it's uses clause.
procedure DoyourThing is only visible to the proceduresand functions in the implementation section of the example unit.

Bart

Navigation

[0] Message Index

[#] Next page

Go to full version