开发者

wx_ref and custom wx_object's

I am developing MDI application with help of wxErlang. I have a parent frame, implemented as wx_object:

-module(main_frame).
-export([new/0, init/1, handle_call/3, handle_event/2, terminate/2]).

-behaviour(wx_object).

....

And I have a child frame, implemented as wx_object too:

module(child_frame).
-export([new/2, init/1, handle_call/3, handle_event/2, terminate/2]).
-export([save/1]).

-behaviour(wx_object).

% some public API method
save(Frame) ->
    wx_object:call(Frame, save).

....

I want to call save/1 for an active child frame from the parent frame. There is my code:

 ActiveChild = wxMDIParentFrame:getActiveChild(Frame),
 case wx:is_null(ActiveChild) of
  false ->
   child_frame:save(ActiveChild);
  _ ->
   ignore
 end

This code fails because ActiveChild is #wx_ref{} with state=[], but wx_object:call/2 needs #wx_ref{} where state is set to the pid of the process which we call. What is the开发者_如何学编程 right method to do this? I thought only to store a list of all created child frames with its pids in the parent frame and search the pid in this list, but this is ugly.


You can not (currently) get the erlang object/process from
wxMDIParentFrame:getActiveChild(Frame),

You will have to keep the erlang Child objects in your state and the active child, as well probably keep it updated with events.

There is room for improvment here

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜