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
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
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!
Hi there
You need to call your function / procedure with unit.procedure -
greet.Salute( ParamStr( index ) )
Hope that helps!
Thanks a lot guys!
Your answers helped a lot!
I figured out that i forgot to declare the procedure in the unit.
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.