, 당신은 OpenWithParm()
에 전달 전용 개체를 만들 수 있습니다 당신은 어떤 파워 오브젝트를 통과 할 수 있기 때문에 그 (message.powerobjectparm
으로 open()
에서 검색 할 수 있습니다 이 방법으로).
확장명으로 open()
이벤트의 이름으로 얻을 수있는 이름이 any
인 임의의 수의 명명 된 매개 변수를 구조를 통해 수신 할 수있는 일반 개체 형식을 만들 수 있습니다. 가난한 사람의 사전의 일종.여기
는 일부 기존 코드를 기반으로 exemple입니다 : (C의 변수 인수 유형 등)
nv_va_arg
객체 - 소스가 오브젝트를 다시 오브젝트 "편집 소스"컨텍스트 메뉴에서 복사,
forward
global type nv_va_args from nonvisualobject
end type
end forward
global type nv_va_args from nonvisualobject autoinstantiate
end type
type variables
private:
string _is_names[]
any _ia_items[]
end variables
forward prototypes
public subroutine add_item (string as_name, any aa_val)
private function integer search (string as_name)
public subroutine set_item (string as_name, any aa_val)
public function any get_item (string as_name)
private subroutine set_item (integer ai_index, string as_name, any aa_val)
public function integer size()
public function string get_name (integer ai_index)
public function any get_item (integer ai_index)
end prototypes
public subroutine add_item (string as_name, any aa_val);
/* add a new item if not already present */
int idx
idx = search(as_name)
if idx = -1 then
idx = upperbound(_is_names) + 1
set_item(idx, as_name, aa_val)
end if
end subroutine
private function integer search (string as_name);
/* search for an item */
int i, n
n = upperbound(_is_names)
for i = 1 to n
if _is_names[i] = as_name then return i
next
return -1
end function
public subroutine set_item (string as_name, any aa_val);
/* public setter */
int idx
idx = search(as_name)
if idx =-1 then
idx = upperbound(_is_names) + 1
end if
set_item(idx, as_name, aa_val)
end subroutine
public function any get_item (string as_name);
/* get the named item */
int idx
any la_val
idx = search(as_name)
if idx > 0 then
la_val = _ia_items[idx]
end if
return la_val
end function
private subroutine set_item (integer ai_index, string as_name, any aa_val);
/* internal setter */
_is_names[ai_index] = as_name
_ia_items[ai_index] = aa_val
end subroutine
public function integer size();
/* return the number of elements */
return upperbound(_is_names)
end function
public function string get_name (integer ai_index);
/* return the name of the nth item */
string ls_ret = ""
if ai_index > 0 and ai_index <= upperbound(_is_names) then
ls_ret = _is_names[ai_index]
end if
return ls_ret
end function
public function any get_item (integer ai_index);
/* get the named item */
any la_val
if ai_index > 0 and ai_index <= upperbound(_is_names) then
la_val = _ia_items[ai_index]
end if
return la_val
end function
on nv_va_args.create
call super::create
TriggerEvent(this, "constructor")
end on
on nv_va_args.destroy
TriggerEvent(this, "destructor")
call super::destroy
end on
- exampl : 다음 코드를 마우스 오른쪽 버튼으로 클릭 "편집 소스"및 붙여 넣기 저장,
nv_va_args
라는 새로운 "사용자 정의 클래스"개체를 추가 의 open()
이벤트에 넣어 검색 인수
nv_va_args lva_args
//set some values
lva_args.add_item("arg_1", 42)
lva_args.add_item("arg_2", "foo bar")
//change a value
lva_args.set_item("arg_2", "foo baz")
openwithparm(w_test, lva_args)
- 2 예 : 매개 변수 충전의 전자, 당신은 어떤 이름과
nv_va_args
객체의 내부 any
배열에 저장됩니다 어떤 유형을 사용할 수 있습니다 창문. message
개체에서 개체 검색은 그 가치를 잃어버린하지 않는 이벤트의 시작 부분에 수행되어야합니다
powerobject lpo_arg //do not create it, as it is autoinstanciated
lpo_arg = message.PowerObjectParm //make immediate copy of the message
nv_va_args lva_args
if isvalid(lpo_arg) and not isnull(lpo_arg) then
lva_args = lpo_arg
end if
//example: enumerate all the parameters
string ls_msg = "", ls_class
int i
any la_val
for i = 1 to lva_args.size()
ls_msg = ls_msg + lva_args.get_name(i) + ': '
la_val = lva_args.get_item(i)
ls_class = classname(la_val)
if ls_class = "string" or ls_class = "long" then
ls_msg = ls_msg + string(la_val, "[general]")
else
ls_msg = ls_msg + '[' + ls_class + ']'
end if
ls_msg = ls_msg + "~r~n"
next
messagebox("list of parameters", ls_msg)
//example: just get a named parameter
string ls_name = "arg_2"
la_val = lva_args.get_item(ls_name)
ls_msg = ls_name + " is " + string(la_val, "[general]")
messagebox("named parameter", ls_msg)
내가해야합니까합니다 (
message
객체는 매우 빠른 속도로 덮어 쓸 수있는 전역 개체입니다) lstr_declaredstr 구조체를 생성 하시겠습니까? –예, 구조를 만듭니다. 매개 변수의 통과에 대한 옵션이 있습니까 –
그리고 w_wantparm에서도 lstr_declaredstr 구조체를 생성해야합니까? –