wx_ref 和自定义 wx_object
我正在 wxErlang 的帮助下开发 MDI 应用程序。我有一个父框架,实现为 wx_object:
-module(main_frame).
-export([new/0, init/1, handle_call/3, handle_event/2, terminate/2]).
-behaviour(wx_object).
....
我有一个子框架,也实现为 wx_object:
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).
....
我想从父框架调用 save/1 来获取活动子框架。这是我的代码:
ActiveChild = wxMDIParentFrame:getActiveChild(Frame),
case wx:is_null(ActiveChild) of
false ->
child_frame:save(ActiveChild);
_ ->
ignore
end
此代码失败,因为 ActiveChild 是 #wx_ref{} 且 state=[],但 wx_object:call/2 需要 #wx_ref{},其中 state 设置为我们调用的进程的 pid。执行此操作的正确方法是什么?我只想在父框架中存储所有创建的子框架及其 pid 的列表,并在此列表中搜索 pid,但这很丑陋。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您(当前)无法从
获取 erlang 对象/进程
wxMDIParentFrame:getActiveChild(Frame)
,您必须将 erlang Child 对象保留在您的状态和活动子对象中,
也可能会随时更新事件。
这里还有改进的空间
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