Recent

Author Topic: [SOLVED] Moving Procedures from one Unit to Another  (Read 2166 times)

guest48180

  • Guest
[SOLVED] Moving Procedures from one Unit to Another
« on: November 27, 2013, 09:57:59 pm »
I've taken some lengthy procedures and placed them in their own units. But I can't figure out how to call them from the main unit, how to let the compiler know they're part of the program.
Any help on this is appreciated.

Landslyde

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4720
  • I like bugs.
Re: Moving Procedures from one Unit to Another
« Reply #1 on: November 28, 2013, 12:04:23 am »
I've taken some lengthy procedures and placed them in their own units. But I can't figure out how to call them from the main unit, how to let the compiler know they're part of the program.

Put the new unit name in "uses" section of your main unit.
Mostly Lazarus trunk and FPC 3.2 on Manjaro Linux 64-bit.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 12616
  • Debugger - SynEdit - and more
    • wiki
Re: Moving Procedures from one Unit to Another
« Reply #2 on: November 28, 2013, 12:08:30 am »

engkin

  • Hero Member
  • *****
  • Posts: 3112
Re: Moving Procedures from one Unit to Another
« Reply #3 on: November 28, 2013, 12:11:28 am »
Assume the new unit is NewUnit1, make the procedure available to other units by putting its declaration before the implementation section:

Code: [Select]
unit NewUnit1;

interface
..
//Here you can make a procedure visible to other units when they use this unit
procedure NewProcedure1(...);
..
implementation

//This procedure is visible outside this unit
procedure NewProcedure1(...);
begin
...
end;

//This procedure is NOT visible outside this unit
procedure NewProcedure2(...);
begin
...
end;



Add the newly created unit to the uses section of the main unit:

Code: [Select]
uses
..., NewUnit1;

call the procedure in your code:

Code: [Select]
...
  NewProcedure1(...);
...

Notice that NewProcedure2 is not visible. Any thing you put after implementation is not visible outside that unit
« Last Edit: November 28, 2013, 12:13:36 am by engkin »

 

TinyPortal © 2005-2018