简体   繁体   English

使用VCL作为Web(intraweb)作为向传统非分层(2层)Delphi win32应用程序添加Web界面的技巧确实有意义吗?

[英]Using VCL for the web (intraweb) as a trick for adding web interface to a legacy non-tiered (2 tiers) Delphi win32 application does make sense?

My team is maintaining a huge Client Server win32 Delphi application. 我的团队正在维护一个巨大的Client Server win32 Delphi应用程序。 It is a client/server application (Thick client) that uses DevArt (SDAC) components to connect to SQL Server. 它是一个客户端/服务器应用程序(胖客户端),它使用DevArt(SDAC)组件连接到SQL Server。

The business logic is often "trapped" in Component's event handlers, anyway with some degree of refactoring it is doable to move the business logic in common units (a big part of this work has already been done during refactoring... Maintaing legacy applications someone else wrote is very frustrating, but this is a very common job). 业务逻辑经常被“陷阱”在Component的事件处理程序中,无论如何,通过一定程度的重构,可以将业务逻辑移动到公共单元中(这项工作的很大一部分已经在重构期间完成了......维护遗留应用程序的人别写的非常令人沮丧,但这是一项非常普遍的工作)。

Now there is the request of a web interface, I have several options of course, in this question i want to focus on the VCL for the web (intraweb) option. 现在有一个Web界面的请求,当然我有几个选项,在这个问题中我想关注VCL for web(intraweb)选项。

The idea is to use the common code (the same pas files) for both the client/server application and the web application. 我们的想法是为客户端/服务器应用程序和Web应用程序使用公共代码(相同的pas文件)。 I heard of many people that moved legacy apps from delphi to intraweb, but here I am trying to keep the Thick client too. 我听说很多人将遗留应用程序从delphi迁移到intraweb,但在这里我也试图保留Thick客户端。

The idea is to use common code, may be with some compiler directives to write specific code: 这个想法是使用通用代码,可能会用一些编译器指令来编写特定的代码:

{$IFDEF CLIENTSERVER}
  {here goes the thick client specific code}
{$ELSE}
  {here goes the Intraweb specific code}
{$ENDIF}

Then another problem is the "migration plan", let's say I have 300 features and on the first release I will have only 50 of them available in the web application. 然后另一个问题是“迁移计划”,假设我有300个功能,在第一个版本中,我将只在Web应用程序中提供50个。 How to keep track of it? 如何跟踪它? I was thinking of (ab)using Delphi interfaces to handle this. 我在想(ab)使用Delphi接口来处理这个问题。 For example for the User Authentication I could move all the related code in a procedure and declare an interface like: 例如,对于用户身份验证,我可以在过程中移动所有相关代码并声明如下界面:

type
  IUserAuthentication= interface['{0D57624C-CDDE-458B-A36C-436AE465B477}']
    procedure UserAuthentication;
  end;

In this way as I implement the IUserAuthentication interface in both the applications (Thick Client and Intraweb) I know that That feature has been "ported" to the web. 通过这种方式,当我在两个应用程序(胖客户端和Intraweb)中实现IUserAuthentication接口时,我知道该功能已经“移植”到Web上。 Anyway I don't know if this approach makes sense. 无论如何,我不知道这种方法是否有意义。 I made a prototype to simulate the whole process. 我制作了一个原型来模拟整个过程。 It works for a "Hello world" application, but I wonder if it makes sense on a large application or this Interface idea is only counter-productive and can backfire. 它适用于“Hello world”应用程序,但我想知道它是否对大型应用程序有意义,或者这种接口的想法只会适得其反并且会适得其反。

My question is: does this approach make sense? 我的问题是:这种方法有意义吗? (the Interface idea is just an extra idea, it is not so important as the common code part described above) Is it a viable option? (接口的想法只是一个额外的想法,它不像上面描述的通用代码部分那么重要)它是一个可行的选择吗?

I understand it depends a lot of the kind of application, anyway to be generic my one is in the CRM/Accounting domain, and the number of concurrent users on a single installation is typically less than 20 with peaks of 50. 据我所知,这取决于很多类型的应用程序,无论如何我是CRM / Accounting域中的通用,并且单个安装上的并发用户数通常少于20,峰值为50。

EXTRA COMMENT (UPDATE): I ask this question because since I don't have a n-tier application I see Intraweb as the unique option for having a web application that has common code with the thick client. 额外评论(更新):我问这个问题是因为我没有n层应用程序,所以我认为Intraweb是拥有一个与胖客户端有共同代码的Web应用程序的唯一选择。 Developing webservices from the Delphi code makes no sense in my specific case, so the alternative I have is to write the web interface using ASP.NET (duplicating the business logic), but in this case I cannot take advantage of the common code in an easy way. 在我的特定情况下,从Delphi代码开发Web服务是没有意义的,所以我可以选择使用ASP.NET编写Web界面(复制业务逻辑),但在这种情况下我无法利用公共代码。简单的方法。 Yes I could use dlls maybe, but my code is not suitable for that. 是的我可以使用dll,但我的代码不适合。

The most important thing that you have to remember is this: 你必须要记住的最重要的事情是:

  • Your thick client .EXE process is used by one person at a time (multiple persons will have multiple instances of that .EXE). 您的胖客户端.EXE进程一次由一个人使用(多个人将有多个.EXE实例)。
  • Your intraweb .EXE process will be used by many persons at a time. 您的intraweb .EXE进程将被许多人一次使用。 They all share the same instance of the process. 它们都共享相同的流程实例。

That means your business logic must not only be refactored out into common units, the instances of the business logic must be able to reside into memory multiple times, and not interfere. 这意味着您的业务逻辑不仅必须重构为公共单元,业务逻辑的实例必须能够多次驻留在内存中,而不是干扰。

This starts with the business logic that talks to the database: you must be able to have multiple database connections at the same time (in practice a pool of database connections work best). 这从与数据库对话的业务逻辑开始:您必须能够同时拥有多个数据库连接(实际上,数据库连接池最有效)。

In my experience, when you can refactor your business logic into datamodules, you have a good starting point to support both an Intraweb and a thick client version of your app. 根据我的经验,当您可以将业务逻辑重构为数据模块时,您有一个很好的起点来支持应用程序的Intraweb和胖客户端版本。

You should not forget the user interface: 你不应该忘记用户界面:

  • Thick clients support modal forms, and have a much richer UI 胖客户端支持模态表单,并具有更丰富的UI
  • Web browsers support only message dialogs (and then: those are very limited), all fancy UI stuff costs a lot of development time (though for instance, TMS has some nice components for Intraweb ) Web浏览器仅支持消息对话框(然后:那些非常有限),所有花哨的UI内容都需要大量的开发时间(例如,TMS有一些很好的Intraweb组件

Then, to top it off, you have to cope with the stateless nature of the HTTP protocol. 然后,最重要的是,您必须应对HTTP协议的无状态特性。 To overcome this, you need sessions. 为了克服这个问题,你需要会议。 Intraweb will take care of most of the session part. Intraweb将负责会话的大部分内容。
But you need to ask yourself questions like these: 但你需要问自己这样的问题:

  • what should happen if a user is idle for XX minutes? 如果用户闲置XX分钟会发生什么?
  • how much session state can I store in memory? 我可以在内存中存储多少会话状态? and what if it doesn't fit? 如果它不适合怎么办?
  • what do I do with the session state that does not fit into memory? 如何处理不适合内存的会话状态?

This is just a start, so let use know when you need more info. 这只是一个开始,所以当你需要更多信息时,请使用知道。
If it gets very specific to your app, you can always contact me directly: just google me. 如果它非常适合您的应用,您可以随时直接与我联系:只是谷歌我。

--jeroen --jeroen

I think if you move your application to n-tiers will be a better solution, it will be easier after that to be used by the desktop and web applications. 我认为如果将应用程序移动到n层将是一个更好的解决方案,那么桌面和Web应用程序将更容易使用它。

you already made the first part by decoupling the business logic from the presentation, you can use RemObject SDK or DataSnap that bundled with Delphi. 通过将业务逻辑与表示分离,您已经完成了第一部分,您可以使用与Delphi捆绑在一起的RemObject SDK或DataSnap。

after that you will have working desktop application, and you can use Intrawebm Asp.net or what ever for web part, and in this way you will not have to duplicate the business logic again for the web part. 之后,您将拥有工作桌面应用程序,并且您可以使用Intrawebm Asp.net或Web部件的任何内容,这样您就不必再为Web部件复制业务逻辑。

usually converting desktop application to web not easy as you thought, because they work in different environment, and you need to build each one as it's nature. 通常将桌面应用程序转换为Web并不容易,因为它们在不同的环境中工作,并且您需要根据其性质构建每个应用程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM