0

Hey Guys,

I'd like to try using function and procedures on my project,
I tried to write them on different unit say unit2 to be used in unit1.
I find a difficulties using them in unit1.

thanks in advance!

Elva

3
Contributors
3
Replies
4
Views
8 Years
Discussion Span
Last Post by elva.tanaem
0

Argh, I couldn't find a simple example on the web. So, without further ado:

hello.dpr

program hello;
{$apptype console}
uses greet;

var
  index: cardinal;
  name:  string;
begin
if ParamCount > 0
  then for index := 1 to ParamCount do
         Salute( ParamStr( index ) )
  else begin
       Write( 'What is your name? ' );
       ReadLn( name );
       Salute( name )
       end
end.

greet.pas

unit greet;

interface
procedure Salute( name: string );

implementation
procedure Salute;
  begin
  WriteLn( 'Hello ', name, '!' )
  end;

end.

Hope this helps. :)

[edit]
Example use: D:\prog\delphi\hello> [b]hello[/b] What is your name? [b]Johnny Five[/b] Hello Johnny Five! D:\prog\delphi\hello> [b]hello Jacob "Mary Ann"[/b] Hello Jacob! Hello Mary Ann!

0

Hi there

You need to call your function / procedure with unit.procedure -

greet.Salute( ParamStr( index ) )

Hope that helps!

0

Thanks a lot guys!
Your answers helped a lot!
I figured out that i forgot to declare the procedure in the unit.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.