Delphi_06_Delphi_Object_Pascal_기본 구문05_함수 매개 변수
프로젝트 파일
{ Delphi
1、
2、
}
program Routine;
{$APPTYPE CONSOLE}
uses
SysUtils,
Unit1 in 'Unit1.pas';
{
1、
}
procedure foo();
begin
WriteLn(' ');
end;
var
nVar1:integer;
nVar2:integer;
varString:string;
begin
//
foo();
// unit1
//writeCurrentDir();
forwardKey_2();
{
1、swapInteger()
2、 IntToStr()
}
nVar1 := 10;
nVar2 := 20;
varString := 'Before swap nVar1 =' + IntToStr(nVar1) +' ;nVar2 =' +
IntToStr(nVar2);
WriteLn(varString);
// ,
swapInteger(nVar1,nVar2);
varString := 'After swap nVar1 =' + IntToStr(nVar1) +' ;nVar2 =' +
IntToStr(nVar2);
WriteLn(varString);
//
varString := 'In the call function the value of nVar1 = ' + IntToStr(nVar1);
WriteLn('Befor call valueProcedure');
WriteLn(varString);
valueProcedure(nVar1);
varString := 'In the call function the value of nVar1 = ' + IntToStr(nVar1);
WriteLn('After call valueProcedure');
WriteLn(varString);
//
constProcedure(100);
//
WriteLn('Before call outProcedure(), nVar2 = ' + IntToStr(nVar2));
outProcedure(1000,nVar2);
WriteLn('After call outProcedure(), nVar2 = ' + IntToStr(nVar2));
ReadLn;
end. 유닛 파일
{
1、
2、
}
unit Unit1;
interface
uses
Windows, //Win32 API
SysUtils; //Delphi
{
1、 , ,
2、 procedure
}
procedure writeCurrentDir();
(*
1、external , DLL、 obj
2、 obj , obj ,
{$L BLOCK.obj}
3、forward , C
, , forward
, C 。
*)
{
forward
}
procedure forwardKey_2();
{
1、 , var
2、 , ,
3、 , const
4、 , out
5、 ; C
}
{
1、 var
2、 , swap
3、
}
procedure swapInteger(var nVar1:integer;var nVar2:integer);
//procedure swapIntegerByPointer();
{
1、
}
procedure valueProcedure(nVar:integer);
{
1、
}
procedure constProcedure(const nVar:integer);
{
1、 Delphi ,
2、 , result 。
3、 ,
4、 out
5、 、
}
procedure outProcedure(nVar1:integer;out nVar2:integer);
implementation
procedure writeCurrentDir();
// ,
var
strPath:WideString;
currentPath:ansistring;
nPathLen:integer;
begin
// ,
SetLength(strPath,255);
WriteLn(strPath);
// , ????,
FillMemory(@strPath,255,0);
// , Win32 API
GetCurrentDirectory(255,PWideChar(strPath));
currentPath:=strPath;
WriteLn(currentPath);
{
1、Delphi
2、 SysUtils ParamStr()
3、 0 , ParamStr()
}
// Delphi , \
currentPath := ExtractFilePath(ParamStr(0));
WriteLn(currentPath);
// \
currentPath := ExTractFileDir(ParamStr(0));
WriteLn(currentPath);
end;
{ forward
1、 , forward
2、 forwardKey_1()
3、 , forwardKey_2() forwardKey_1()
}
procedure forwardKey_1();forward;
procedure forwardKey_2();
begin
WriteLn('Call forwardKey_1() by used forward keyword.');
forwardKey_1();
end;
procedure forwardKey_1();
begin
WriteLn('This is forwardKey_1().');
end;
{
1、swap
}
procedure swapInteger(var nVar1:integer;var nVar2:integer);
var
nVar:integer;
begin
nVar := nVar1;
nVar1 := nVar2;
nVar2 := nVar1;
end;
{
1、
}
procedure valueProcedure(nVar:integer);
var
str:string;
begin
str:='Before change in function valueProcedure nVar= ' + IntToStr(nVar);
WriteLn(str);
nVar := 100;
str := 'After change in function valueProcedure nVar= ' +IntToStr(nVar);
WriteLn(str);
end;
{
1、
2、 C , ,
}
procedure constProcedure(const nVar:integer);
var
nVar1:integer;
begin
// nVar const,
//nVar:=300;
// 。
nVar1:= nVar;
WriteLn('nVar1 = ' + IntToStr(nVar1));
end;
{
1、 out
2、 PLC ,
}
procedure outProcedure(nVar1:integer;out nVar2:integer);
begin
nVar2 := nVar1;
end;
end. 전재를 환영합니다. 전재는 출처를 밝혀 주십시오.