wx_ref 和自定义 wx_object

发布于 2024-09-04 17:25:50 字数 880 浏览 5 评论 0原文

我正在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

吃→可爱长大的 2024-09-11 17:25:50

您(当前)无法从
获取 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文