Delphi Clinic C++Builder Gate Training & Consultancy Delphi Notes Weblog Dr.Bob's Webshop
Dr.Bob's Kylix Kicks
 Borland C++Builder lost+found #13
See Also: C++Builder Papers and Columns

No such luck... yet
Now for something completely different. Normally I do C++ stuff, this time I'll do Delphi stuff and take it from there to C++ stuff permitting you do not have C++Builder Enterprise but still want to use the idiom. What idiom? The CORBA bind in a property idiom.

Use CORBA wizard
In C++Builder Enterprise 4 you can use Visibroker. It also has a wizard that let's you use a CORBA object in a form. It uses a property that you use to get at the methods exposed by a CORBA server object. To find it, right click in the toolbar and turn on the CORBA toolbar. The icons with the blue bubble says 'Use CORBA Object'. If you use that wizard, it will lead you through a number of options. What you may end up with is a property in your form. From the following IDL

  module Conference
  {
    interface Session
    {
      attribute string Name;
    };
  };
it can make this:
  class TFormMain: public TForm
  {
  private:
    Conference::Session_ptr __fastcall GetSession();
    Conference::Session_var FSession;
    void __fastcall SetSession(Conference::Session_ptr _ptr);
  public:
    __property Conference::Session_ptr Session =
    {
      read=GetSession,
      write=SetSession
    };
  };
The implementation is this:
  Conference::Session_ptr __fastcall TFormMain::GetSession(void)
  {
    if (FSession == NULL)
    {
       FSession = Conference::Session::_bind("ConferenceSession");
    }
    return FSession;
  }

  void __fastcall TFormMain::SetSession(Conference::Session_ptr
  _ptr)
  {
    FSession = _ptr;
  }
If you use the property, it will automagically bind to the server object for you. Even better, since it uses a Conference::Session_var as a variable, the object will be released automatically.

Enter Visibroker for Delphi
Inprise recently released a tool for Delphi with which you can create CORBA clients. However, no wizard is included in this package. No such lucků yet. Maybe in the next issue of Delphi. It is more or less a command line tool that generates the client stubs in Delphi instead of something else. However, you might use the same method to bind to server objects in your own forms:

  type
    TConfClntForm = class(TForm)
      EditConfName: TEdit;
      procedure FormActivate(Sender: TObject);
    private
      { Private declarations }
      FSession: Conference_i.Session;
      function GetSession: Conference_i.Session;
      procedure SetSession(iface: Conference_i.Session);
    public
      { Public declarations }
      property Session: Conference_i.Session
        read GetSession
        write SetSession;
    end;

  var
    ConfClntForm: TConfClntForm;

  implementation

  {$R *.DFM}
  function TConfClntForm.GetSession: Conference_i.Session;
  begin
    if (FSession = nil) then
      FSession := TSessionHelper.Bind('ConferenceSession');
   Result := FSession;
  end;

  procedure TConfClntForm.SetSession(iface: Conference_i.Session);
  begin
    FSession := iface;
  end;
If we want to use it:
  procedure TConfClntForm.FormActivate(Sender: TObject);
  begin
    EditConfName.Text := Session.Name;
  end;
Back to C++, straight this time
If you don't want to use C++Builder like C++, you also can wrapper client calls to CORBA objects in the following way. It sort of emulates the __property extension:
  class Wrapper
  {
  public:
    Conference::Session_ptr Session()
    {
      if (sv == 0)
      {
        sv = Conference::Session::_bind("ConferenceSession");
	      }
            return sv;
    }
    void Session(Conference::Session_ptr ptr)
    {
      sv = ptr;
    }
  private:
    Conference::Session_var sv;
  };

This webpage © 2000-2017 by Bob Swart (aka Dr.Bob - www.drbob42.com). All Rights Reserved.