2017-01-09 4 views
0

다음은 단일 매개 변수를 다른 pb 창 객체에 전달하기위한 코드입니다. dw_header에서Powerbuilder에서 OpenWithParm의 다중 매개 변수 전달

단일 매개 변수를 전달에 w_customer_balance open 이벤트

long ll_id 
datetime dt_from, dt_to 
ll_id = message.doubleparm 
dw_1.settransobject(sqlca) 
dw_1.retrieve(ll_id) 

이 완벽하게 작동 벌금 이벤트

long ll_customer 
datetime dt_from, dt_to 
ll_customer = getitemnumber(1,"customer_id") 
dt_from = datetime(date(f_today()),time('00:00:00')) 
dt_to = datetime(date(f_today()),time('23:59:59.99')) 

openwithparm(w_customer_balance,ll_customer) 

를 클릭했습니다. 하지만 다른 매개 변수를 전달하려는 경우 dt_fromdt_to을 고객 잔금 창에 입력하십시오.

아무도 없습니까?

답변

1

여러 매개 변수를 전달해야하는 경우, 다음이 방법을 사용할 수 있습니다 :

구조 변수의 정의 : lstr_declaredstr, 당신은 매개 변수를 전달하려면 포함

변수 유형 변수 이름 :

ID Unsignedlong; 이름 문자; 이메일 문자; 홈페이지 문자

...

스크립트, 다음 코드를 사용 호출 :

lstr_declaredstr lstr_parmtotrans 
lstr_parmtotrans.id = 1 
lstr_paramtotrans.name = "panya" 
lstr_paramtotrans.email = "[email protected]" 
lstr_paramtotrans.homepage = "http://panya.163.net" 

을 ...

openwithparm (w_wantparm, lstr_paramtotrans) 

는 그 다음 w_wantparm 열린에게있는 창을 엽니 다 경우, 구조 정보를 얻으려면 :

lstr_declaredstr lstr_getparm 
integer li_getid 
string ls_getname 
string ls_getemail 
string ls_gethomepage 
lstr_getparm = message.powerobjectparm 
li_getid = lstr_getparm.id 
ls_getname = lstr_getparm.name 
ls_geemail = lstr_getparm.email 
ls_gethomepage = lstr_getparm.homepage 

더 많은 예제를 보려면 web

+0

내가해야합니까합니다 (message 객체는 매우 빠른 속도로 덮어 쓸 수있는 전역 개체입니다) lstr_declaredstr 구조체를 생성 하시겠습니까? –

+0

예, 구조를 만듭니다. 매개 변수의 통과에 대한 옵션이 있습니까 –

+0

그리고 w_wantparm에서도 lstr_declaredstr 구조체를 생성해야합니까? –

1

인스턴스 변수로 비 시각적 객체를 정의한 다음 Openwithparm 메소드 호출로 전달할 수도 있습니다. 호출 된 윈도우는 nvo가 (일반적으로 인스턴스 변수로) 생성 된 다음 powerobjectparm 매개 변수 유형을 통해 열린 이벤트에서 '수신'되어야합니다. 대신 창으로 몇 가지 매개 변수를 전달을 위해 특별히 구조를 정의하는, 매트 Balent에 의해 제안

+0

i D : 파워 빌더에 조금 미안해. 샘플을 제공해 줄 수 있니? –

0

, 당신은 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) 
+0

왜 downvote인가? 내 대답은 묻는 질문에 완벽하게 적합하다. – Seki