마음의 안정을 찾기 위하여 - 델파이 함수 호출시 Return 값으로 배열 사용하기
2279356
1112
952
관리자새글쓰기
태그위치로그방명록
별일없다의 생각
dawnsea's me2day/2010
색상(RGB)코드 추출기(Color...
Connection Generator/2010
최승호PD, '4대강 거짓말 검...
Green Monkey**/2010
Syng의 생각
syng's me2DAY/2010
천재 작곡가 윤일상이 기획,...
엘븐킹's Digital Factory/2010
델파이 함수 호출시 Return 값으로 배열 사용하기
My Library | 2007/09/06 10:54
출처 : http://delphi.about.com/od/delphitips2007/qt/array_parameter.htm

델파이에 함수의 리턴값에 배열을 사용하는 방법에 대해 설명하고 있다.
델파이에서 함수의 리턴값 설정시 "function GetWeekTotal(weekIndex : integer) : array[0..6] of integer;
"와 같은 형태로 사용하게 되면, 컴파일 에러를 발생시키며 컴파일이 진행되지 않는다.

때문에 함수의 리턴값으로 Array(배열)을 사용하기 위해서는 Array를 Type 선언한후, 해당 Type으로 리턴받으면 된다.

[선언부]
type
  TDayVisitors = array[0..6] of integer;

[사용시]
function GetWeekTotal(weekIndex : integer) : TDayVisitors;



Arrays in Delphi allow us to refer to a series of variables by the same name and to use a number (an index) to tell them apart.

Here's an example integer array that can hold up to 7 (integer) values. Note: this is a fixed-size static Delphi array declaration.

var DayVisitors : array[0..6] of Integer;

Arrays as Function Return Types

In Delphi, functions are routines that return a value.

When you want a function to return an array type variable, you might be tempted to use the next declaration:

function GetWeekTotal(weekIndex : integer) : array[0..6] of integer;
begin
  //this will NOT compile
end;
When you try to compile this code, you'll get the next compile-time error: [Pascal Error] E2029 Identifier expected but 'ARRAY' found.

Obviously, when you declare functions that will return array value, you cannot include index type specifiers return declaration.

In order to allow a function to return an array value, you first need to create a custom array type, then use it as a return function type:

//this WILL compile
type
  TDayVisitors = array[0..6] of integer;

...

function GetWeekTotal(weekIndex : integer) : TDayVisitors;
begin
  //do some calculation for the provided "week"
end;

Arrays as Method/Routine Properties

Similar to using arrays as function return types, when you declare routines that take array parameters, you cannot include index type specifiers in the parameter declarations.
type
  TDayVisitors = array[0..6] of integer;

...

procedure DisplayWeekTotal(weekVisitors : TDayVisitors) ;
begin
  //display some info for the provided "week"
end;

2007/09/06 10:54 2007/09/06 10:54
Article tag list Go to top
View Comment 0
Trackback URL :: 이 글에는 트랙백을 보낼 수 없습니다
 
 
 
 
: [1] ... [9][10][11][12][13][14][15][16][17] ... [32] :
«   2024/04   »
  1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30        
전체 (1317)
출판 준비 (0)
My-Pro... (41)
사는 ... (933)
블로그... (22)
My Lib... (32)
게임 ... (23)
개발관... (3)
Smart ... (1)
Delphi (93)
C Builder (0)
Object... (0)
VC, MF... (10)
Window... (1)
Open API (3)
Visual... (0)
Java, JSP (2)
ASP.NET (0)
PHP (5)
Database (12)
리눅스 (29)
Windows (25)
Device... (1)
Embedded (1)
게임 ... (0)
Web Se... (2)
Web, S... (21)
잡다한... (6)
프로젝트 (0)
Personal (0)
대통령... (13)
Link (2)