Tuesday, December 26, 2006

파워빌더의 미약한 다형성(多形性, polymorphism)

데이타스토어는 업데이트시 에러가 나면 오류를 가로체지를 못한다.
가로 채려면 표준데이타스토어를 상속 받은 클래스를 사용 하여 DBerror 이벤트 부분에 처리 부분을 기술 해 주어야만 가능 하다.

이것을 자바의 핸들러 식으로 처리 할 수 없나 하고 알아보다 다형성을 생각 해 보았다.

하지만,

파워빌더는 다중 상속이 되지 않는다.
오로지 단일 상속이다.

더욱 않좋은 것은(?) 강제로 캐스팅도 불가능 하다.

따라서 자바의 implement나 c++의 가상 함수 같은 것은 구현이 불가 하다.

하지만, dynamic이라는 키워드를 사용하여 흉내는 낼 수 있다.

다음의 예를 보자

오브젝트는 아래와 같이 구성 하였다.
application
window w_1
window w_showmsg

w_1는 (none)showmessage(string as_1) 윈도함수를 가지고 있다.
내용은 MessageBox("", as_1) 이 한 줄을 가지고 있다.

w_showmsg도 (none)showmessage(string as_1) 윈도함수를 가지고 있다.
다만 내용은 없다.

아래는 application에 코딩한 내용이다.

1 w_showmsg lw_showmsg
2 w_1 lw_1

3 Open(lw_1, "w_1")
4 lw_showmsg = lw_1
5 lw_showmsg.showmessage("abc")

요렇게 하면 컴파일시에는 오류가 발생하지 않는다.
하지만 실행 하면 4번 줄에서 문제가 발생한다. 오류 내용은 “할당하려고 하지만 타입이 일치 하지 않는다” 이다. 타입이 달라 실행시간에 할당 자체가 허락 되지 않는다.

다음과 같이 바꾸어 보았다.

1 w_showmsg lw_showmsg
2 w_1 lw_1
3 window lw_window

4 Open(lw_1, "w_1")
5 lw_window = lw_1
6 lw_window.showmessage("abc")

이번에는 컴파일 해보면 6번 줄에서 오류가 난다. "Unknown function name:showmessage" 즉 없는 메소드, 아니 함수를 호출 한다 이 소리다.

그럼 어쩌면 될까?
이때 바로 dynamic 키워드를 쓰면 된다.
다음과 같이
1 w_showmsg lw_showmsg
2 w_1 lw_1
3 window lw_window

4 Open(lw_1, "w_1")
5 lw_window = lw_1
6 lw_window.dynamic showmessage("abc")
컴파일도 되고 실행도 잘 된다.

그럼 6번줄에서 showmessage 함수를 살짝 바꾸어 s1howmessage로 하면 어찌 될까?
컴파일은 잘 된다. 실행하면 다음과 같은 메시지가 뜬다.





말 그대로 동적으로 함수를 호출 하려 하였으나 해당 함수가 없다. 고로 참조나 잘못 된게 없나 찾아 봐라 이소리다.

dynamic과 try 구문을 이용하면 다형성을 조금이나마 흉내 낼수 있지 않을까 생각 해 본다.

Thursday, December 21, 2006

windowname.ParentWindow()

Description
Obtains the parent window of a window.
Controls
Window objects

Syntax
windowname.ParentWindow()




ArgumentDescription


windownameThe name of a window for which you want to obtain the parentobject


Return value
Window. Returns the parent of windowname. Returns a null object reference if an error occurs or if windowname is null.

Usage
The ParentWindow function, along with the pronoun Parent, allows you to write more general scripts by avoiding the coding of actual window names. Parent refers to the window that contains the current object or control - the local environment. ParentWindow returns the parent window of a specified window.

Whether a window has a parent depends on its type and how it was opened. You can specify the parent when you open the window. For windows that always have parents, PowerBuilder chooses the parent if you do not specify it. Response windows and child windows always have a parent window. The parent of a sheet in an MDI application is the MDI frame window. Pop-up windows have a parent window when they are opened from another window but when used in an MDI application, the parent of the pop-up is the MDI frame. A pop-up window opened from the application's Open event does not have a parent.

The ParentWindow property of the Menu object can be used like a pronoun in Menu scripts. It identifies the window with which the menu is associated when your program is running. For more information, see the PowerBuilder User's Guide.


이 함수는 윈도우 콘트롤에서만 쓸 수 있다.

ParentWindow함수는 Parent 키워드와 함께 실질 적인 윈도 이름을 쓰는 것을 피하고 보다 범용적인 코딩을 할 수 있게 한다.

Parent 는 객체(Object)나 콘트롤(Control)을 담고 있는 윈도를 참조 할 수 있다.

ParentWindow는 지정된 윈도우의 부모 윈도를 돌려 준다.

윈도가 부모를 가질 지 말지는 그 윈도우의 타입 혹은 윈도우가 어떻게 열렸는지에 달렸다.

윈도우를 열적에 부모 윈도우를 기술 할 수 있다.

항상 부모 윈도우를 가져야 하는 윈도우들의 경우, 우리가 부모 윈도우를 알려 주지 않으면, 파워빌더가 부모 윈도우를 선택 한다. Response windows와 child windows는 항상 부모 윈도우를 갖는다. MDI application에서 쓰이는 Sheet의 부모는 MDI Frame Window이다.
Pop-up Window는 다른 window에 의 해 열렸을 경우, 부모 윈도우를 갖는다. 단, MDI application이라면 Pop-up의 부모는 MDI Frame이다.

또한, application의 Open Event에서 열린 Pop-up window의 경우는 부모 윈도우를 갖지 않는다.

Menu Object에서는 ParentWindow가 명사 처럼 사용 될 수 있다.

이 경우 실행 단계에서의 메뉴와 관계 있는 윈도우를 구분 한다.


** Response와 child 형 윈도우는 항상 부모 윈도우를 갖는다 하였는데.. 내가 해 본 바에 의하면 child는 MDI에서 sheet상에서 열렸을 경우, 부모 윈도우로 해당 sheet를 돌려 준다. 하지만 response윈도우는 MDI Frame를 돌려 준다. 버그 인가? 설명이 잘못 된 것인가? 아뭏든 그렇다.

내가 당면한 문제는 윈도우 타입을 child로 놓고 화면을 OpenWithParm으로 띄우니, single line edit가 마우스로 찍어서는 입력이 되지 않는 다는 것이다. 그래서 Response 타입으로 놓으니, 부모 윈도우에서 가져 오는 것을 가져 오지 못하여 오류가 발생 한다.

위의 문제 점으로 ParentWindow()를 쓰면 MDI Frame을 돌려 주므로 여기에 GetActiveSheet()까지 써서 해당 부모 윈도우 타입의 변수에 할당(cast)하여 처리 하였다.

sle에 입력도 잘 되고 부모 윈도우에서 데이타도 잘 가져 온다.

Monday, November 20, 2006

Make column in datawindow transparent

아래 내용은 PBDN.NET에서 검색 한 내용 입니다.

http://www.pbdn.net/board/BoardShow.aspx?board_id=2&role=qna&page=1&c_id=4540&c_seq=2&sfield=total&svalue=%c5%f5%b8%ed

김주영님이 2005-02-22 오후 12:02:09에 남기신 글입니다.
Re:특정 문자를 투명하게 ?
>어느 특정 칼럼을 투명하게 나타낼수 있는 방법좀
>알려주시면 고맙겠습니다.
>

방금 스승님한태 전수받아 왔습니다

우선 "특정"컬럼만 투명하게 한다면 Modify를 사용해야하는건 아시죠??

Modify에서 ObjectName.BackGround.Color를 1087434968 값으로 주면

투명색이 됩니다

string ls_m= "wk_code.Background.color=~"1087434968~t if(wk_code='99991',RGB(254,252,175),1087434968)~""
dw_1.modify(ls_m)

============================================================
1087434968 을 16진수로 변환 하면 40D0F0D8 인데

40 다음이 RGB 값 인것 같다.
40은 RGB에서 표현 할 수 없는 값인데, 이진수로 표현 하면
아래 와 같다.
0100 0000

여기서 1이 있는 부분이 Background.Mode부분이 아닌가 싶다.
테스트 해 본 것에 의하면
40 00 00 00 = 1073741824
값을 넣어도 투명 설정이 가능 하다.

Sunday, September 24, 2006

A Bug of PowerBuilder 9

DataWindow is all of The PowerBuilder.

It is very Powerfull Component.

But PowerBuilder 9 Has a Bug on DataWindow with Group Part.

If i Scrolled DataWindow control what has a DataWindow with a Group, Then there are space between rows of in Scroll View.

I was asked