{"id":98,"date":"2004-04-14T14:41:18","date_gmt":"2004-04-14T04:41:18","guid":{"rendered":"http:\/\/www.malcolmgroves.com\/blog\/?p=98"},"modified":"2004-04-14T14:41:18","modified_gmt":"2004-04-14T04:41:18","slug":"com-in-d7-and-d8","status":"publish","type":"post","link":"http:\/\/www.malcolmgroves.com\/blog\/?p=98","title":{"rendered":"COM in D7 and D8"},"content":{"rendered":"<p>I&#8217;ve been doing some exploration around migration issues from Delphi 7 (Win32) to Delphi 8 (.NET). Yes, VCL for .NET covers a whole bunch of stuff and makes migration a whole bunch easier than it is for other languages, but there are still things you can do in Delphi 7 code that won&#8217;t migrate seamlessly to Delphi 8.<\/p>\n<p>Today, I sat down to look at moving a COM client from Delphi 7 to Delphi 8. I started with a nice, simple scenario. A COM object called BasicSrv, which exposes an Add method. Add takes 2 parameters, x and y, both integers and returns another integer. Hardly staggering stuff, but ever since I started using DCE years ago, through DCOM, CORBA, COM+, J2EE, whatever, this simple scenario has been my &quot;Hello World&quot;.<\/p>\n<p>Once I had this COM object in Delphi 7, I created a Delphi 7 client. Again, very simple. Two edit boxes, a button and a label. Click the button, we create an instance of the COM object and call Add, shoving the results back into the label. The code looks like this:<\/p>\n<p>implementation<\/p>\n<p>uses Server_TLB;<\/p>\n<p>{$R *.dfm}<\/p>\n<p>procedure TForm1.Button1Click(Sender: TObject);   <br \/>var    <br \/>&#160; basicSrv : IBasicSrv;    <br \/>begin    <br \/>&#160; basicSrv := CoBasicSrv.Create;    <br \/>&#160; Label1.Caption := IntToStr(basicSrv.Add(StrToInt(Edit1.Text),     <br \/>StrToInt(Edit2.Text)));    <br \/>end;<\/p>\n<p>Like I said, nice and simple.<\/p>\n<p>So then I went to get the client working in Delphi 8 under .NET. I&#8217;m a little ashamed to admit, I didn&#8217;t expect the experience to be very pleasant, as it seemed like way too much &quot;stuff&quot; had changed under me in the move from Win32 to .NET for this to be anything but painful. Anyway, I opened the Delphi 7 project in Delphi 8, removed the Server_TLB unit from my project and added a reference to my COM object. Surprisingly, the code needed to call this COM object from .NET looked like this (the bits that changed are in bold):<\/p>\n<p>implementation<\/p>\n<p>uses <strong>Server<\/strong>;<\/p>\n<p>{$R *.dfm}<\/p>\n<p>procedure TForm1.Button1Click(Sender: TObject);   <br \/>var    <br \/>&#160; basicSrv : IBasicSrv;    <br \/>begin    <br \/>&#160; basicSrv := <strong>BasicSrvClass<\/strong>.Create;    <br \/>&#160; Label1.Caption := IntToStr(basicSrv.Add(StrToInt(Edit1.Text),     <br \/>StrToInt(Edit2.Text)));    <br \/>end;<\/p>\n<p>All that changed was my unit name and the class name. And I suspect that if I paid a little more attention while adding my reference (or used tlbimp directly), I may have got away with no code changes. How cool is that? <\/p>\n<p>I&#8217;ll be spending a bit more time with examples that are a little more complicated, but I&#8217;m really encouraged, and a little ashamed of myself for doubting \ud83d\ude42<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;ve been doing some exploration around migration issues from Delphi 7 (Win32) to Delphi 8 (.NET). Yes, VCL for .NET covers a whole bunch of stuff and makes migration a whole bunch easier than it is for other languages, but there are still things you can do in Delphi 7 code that won&#8217;t migrate seamlessly [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-98","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"http:\/\/www.malcolmgroves.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/98","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.malcolmgroves.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.malcolmgroves.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.malcolmgroves.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/www.malcolmgroves.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=98"}],"version-history":[{"count":0,"href":"http:\/\/www.malcolmgroves.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/98\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.malcolmgroves.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=98"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.malcolmgroves.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=98"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.malcolmgroves.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=98"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}