25 Years of Programming Community Forum
Blog  Sitemap  Services
May 25, 2013, 04:24:28 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: If you get a (403 - Forbidden) error while trying to browse the forum, it is because your browser is disallowing cookies.
 
   Home   Help Search Login Register  
This is a link to the Chat Room (for Firefox+ChatZilla) when you are logged in.
View help topic about using Live Chat
Pages: 1   Go Down
  Print  
Author Topic: Issues involved in converting Borland OWL to Visual C++  (Read 7018 times)
0 Members and 1 Guest are viewing this topic.
SteveW
Administrator
Sr. Member
*****
Offline Offline

Posts: 285


WWW
« on: March 12, 2010, 05:31:46 AM »

This exchange with all identifying details removed discusses some of the issues to consider when contemplating a code conversion from Borland ObjectWindows Library (OWL) to a newer framework like Microsoft Foundation Class Library (MFCL) or .NET or OWLNext.
« Last Edit: March 13, 2010, 01:12:38 AM by SteveW » Report to moderator   Logged
SteveW
Administrator
Sr. Member
*****
Offline Offline

Posts: 285


WWW
« Reply #1 on: March 12, 2010, 05:35:51 AM »

The good news and the bad in your code:

The good

--Although the program is based on the OWL framework and is structured in C++ style, there are many calls to C functions like strcpy() that should mostly not require conversion. If it had used the Borland C++ string class, the newer standard equivalent is basic_string, which is sufficiently different (and lacks equivalents for some of the old Borland string:: member functions) that a conversion could involve quite a bit of code-tweaking.

--Although the program is based on OWL, there are places where Windows API functions are used instead of OWL methods. Examples include ::MessageBox, ::ShowWindow, ::RedrawWindow. This, too, should avoid the need for some conversion work.

--The code does not appear to use Borland's BIDS container classes for arrays/vectors.

That mostly summarizes the good news.

The bad

--A "conversion" from OWL to .NET is really a rewrite rather than a conversion.

This quote from one of my web pages was targeted mainly at hobbyists converting relatively small programs:

Quote
It's surprising how easy it is to convert old Borland code to Microsoft Visual C++. Text substitutions in the code are often all that's required to convert Borland's BIDS TArray classes to STL. Screen elements like menus must be built from scratch in the VCPP design interface, but it's easy. The hard part was designing the menus in the first place, and that's already done. Learning the new .NET Framework equivalents of the OWL methods can be difficult and time-consuming, but the .NET methods are incredibly powerful and the results are very good.
When scaled up beyond the hobbyist level, it can get more complicated. What is easy to do once or twice becomes a large task if you must do it dozens or hundreds of times. Easy chores in a simple program can be more complicated in a larger and more complex one. Recreating one menu in a small program is indeed easy. Recreating a menu system in which items or submenus are merged, updated, or replaced depending on which "mode" a program is in gets a lot more complicated.

Some of the basic steps of an OWL to .NET conversion are:

1. Every GUI must be built completely from scratch. The entire screen interface has to be replicated using Windows Forms rather than the OWL TFrameWindow/TWindow hierarchy. Each dialog box becomes a new Windows Form rather than a TDialog, and must be designed graphically. Visual Studio does make the graphic design much easier than it was in the old IDE, so the process really is replication of the old design into a new framework, not a completely new design, but that is less comforting if there are 100 different dialog boxes that need replication.

2. Properties, such as of windows, dialogs, and other objects, are assigned within the IDE. This is usually done by examining the properties in the old OWL version, and entering the comparable values in the new IDE design interface. If you start with a copy of the code base, and delete code as you create its equivalent in the new IDE, you know that you're done when you run out of old code.

3. Event handlers are easier to assign than they were in OWL, but the methods of creating them are different. The procedure is to create the object in the IDE, click the event for which you want to create a handler. The function is created for you. Then you copy and paste the old OWL code into the new function and revise any other aspects of it that require conversion to .NET. The fact that you can copy and paste old code saves a lot of time. The fact that you must examine the code after pasting and resolve what might be significant incompatibilities makes the time savings less substantial.

Basically, the process involves creating an entirely new program framework based on Windows Forms and its Properties/Methods/Events structure, and then copying and pasting blocks of old code in the places where they belong in the new program.

What can't be avoided is that all of the lines of code have to be copied and pasted into new locations by a person. After that is done, the compiler can help find old methods that require additional conversion, but the incompatibilities found have to be resolved by a person.

In essence, the conversion to .NET is a large undertaking, even if it's a lesser magnitude problem than writing the program in the first place. The project could be compared to translating the complete works of Shakespeare into French. It's not as difficult as creating the works in the first place, but it's still a big task. Some parts of it can possibly be automated, but every bit of the translation must then be examined for idiomatic expressions that translated poorly, and corrected by someone very familiar with both languages.

-----

You didn't mention what prompted the desire to do a conversion or what other options you might have considered. Here are the possibilities:

1. No conversion, no change. This runs the risk of your current development environment (which might consist of an old computer and the Borland 4.5 IDE running on an old Windows version) becoming increasingly obsolete and dependent on the continued functioning of that one computer, which could fail.

2. Convert the project to Microsoft's Foundation Class Library. This was the competitor to OWL in the 1990's. Microsoft still supports it in Visual Studio. The reason I wouldn't take this route is that a) although there appear to be many similarities between OWL and MFC, I have seen it said that there is no direct mapping from objects in one library to similar objects in the other; thus, the conversion could be as difficult as the one to .NET, but with less of a "forward-looking" result, b) it is C++ only, not language-neutral like .NET, and c) if a conversion is to be done, .NET is more of a "library of the future" than MFC is.

3. Convert your development environment, and the project, to OWLNext (http://owlnext.sourceforge.net/index.html). OWLNext projects can be built and worked with in Visual Studio. This might be a viable conversion option, much lower in cost than a .NET conversion while extending the lifespan of your existing code into the future.

4. .NET conversion. Very expensive, but it upgrades the codebase to a form that should be completely modern and upgradeable for many more years. The type of conversion that makes sense is "mixed mode", containing a mix of .NET managed and (non-.NET) unmanaged code. I believe the cost of converting your program to 100% .NET managed code would be astronomical. For example, it would involve converting ALL the C-style strings (char arrays using functions like strcpy()) to the managed .NET String class, and all C functions such as strcpy() and fread() to the methods of .NET classes.

-----

When I discovered that my OWL code was obsolete, I looked into OWLNext but decided that it was a poor option for me because my primary goal was to learn newer technology than what I was already familiar with. Preserving the functionality of my old code was secondary. I tried a Java conversion but was dissatisfied with Java. I bought and tried Borland C++ Builder 6, but disliked their VCL and its roots in PASCAL, and disliked Borland for having abandoned OWL. It took more than 3 years to decide that my best path was to stick with C++, switch to Microsoft, and use .NET as the best avenue "to the future".
« Last Edit: March 13, 2010, 01:25:55 AM by SteveW » Report to moderator   Logged
SteveW
Administrator
Sr. Member
*****
Offline Offline

Posts: 285


WWW
« Reply #2 on: March 12, 2010, 05:37:51 AM »

Quote
Conversion seems to be too involved and expensive. Is there a way to continue to work with and recompile our old code, given that we no longer have our Borland C++ compiler?
« Last Edit: April 06, 2012, 04:04:19 AM by SteveW » Report to moderator   Logged
SteveW
Administrator
Sr. Member
*****
Offline Offline

Posts: 285


WWW
« Reply #3 on: March 12, 2010, 05:52:14 AM »

Here are some leads that might be useful.

1) While looking at your Borland .IDE file in the Borland 4.0 IDE on my Windows 3.1 computer, one of the things I did was generate a MAKEFILE from it. All I wanted was a text equivalent of the Borland .IDE file that I could view more easily on my Windows XP computer, but for your purposes I think it will help build the project. I don't know if any of the commands need revision due to the fact that my 4.0 IDE is a couple versions older than the 4.5 IDE in which the project was designed. My Borland IDE didn't have any complaints about opening your file, and the makefile has a "normal" look to it.

2) Then you need a compiler that can compile from the .MAK file. Borland (now CodeGear/Embarcadero Technologies) has its C++ 5.5 compiler available free at http://www.codegear.com/downloads/free/cppbuilder. You'll need to log in or register at CodeGear (formerly Borland Developer Network, BDN). This is a console (command line) compiler, not an IDE.

3) You will also need the OWL source code. I discovered today that Borland has released it publicly. This was a big discovery. It took them years to get past the issues, probably legal, that were blocking its release. If you think you will ever need this code, you should download it now. It's at http://cc.codegear.com/item/24574. Until this release, the only way to get OWL (and thus also a prerequisite to using OWLNext) was to find an old Borland C++ version on eBay. As recently as a couple of years ago, there were always dozens available and it was easy to distinguish the legitimate copies from probably pirated versions. Yesterday I found only 2, and they both looked questionable.

4) OWLNext is at http://owlnext.sourceforge.net/index.html.

What you're trying to do might still not be easy, but these could be some of the tools you'll need.

Another possible route:  On the unlikely chance that you still have the .OBJ files from the original project, you might be able to re-link the project in such a way as to override the aspects of the program that you want to modify. If you write a new function of the same name and compile it, it might be possible to include it in the link in such a way that it takes the place of the older version of the function... or it might not work, and generate an unresolvable Duplicate Definition error instead. I don't really remember what to expect or if this is possible.
« Last Edit: March 13, 2010, 01:32:35 AM by SteveW » Report to moderator   Logged
SteveW
Administrator
Sr. Member
*****
Offline Offline

Posts: 285


WWW
« Reply #4 on: March 12, 2010, 06:01:53 AM »

About the .MAK file

I believe a .MAK file is an input file to the MAKE.EXE utility. Check the BC5 installation directories, probably the \Bin folder, for that program. If it's there, run it like this to get a Help screen:

C:\...>MAKE.EXE /?

If you don't have MAKE.EXE, you'll need to either run the compiler hundreds of times (to execute each of the individual compiles and links that are specified in the .MAK file), or possibly construct a long MSDOS .BAT file to execute the sequential compile and link commands, or obtain MAKE.EXE. It's been included in both the Borland compilers I've bought, so I assume it would be in the current C++ Builder package (Builder 2007, I think).

Quote
Do I need the OWL source code just to recompile my program?

Your source files contain references to OWL objects, so they need the OWL code that's in the OWL object libraries that you probably don't have anymore. In order to recompile your program, you'll need to have either the .obj libraries or the source code that you can compile to create those libraries.

The above is a reasoned guess about what's required, and it's just about at the limit of my knowledge. I've not installed OWL 5 into Borland C++ Builder 6, nor installed OWLNext, nor tried to resurrect any of my own OWL programs in Win32. Part of the reason was that until now I didn't realize OWL 5 had become available. The other part was the daunting complexity of the above installations. Be prepared that this is a big job that is probably going to take quite a while.

Borland completely dropped its support of OWL about 10 years ago. Although they've now released the code, they still no longer support it, and have not designed any of their products to accommodate it or make its use easy, so putting together an OWL system is like trying to restore an antique car from scavenged parts.

If I decide to resurrect my old programs (no more than a few hundred to a few thousand lines each), I'll probably allow a week of full time research and configuration to install OWL 5, at least another week to install and configure OWLNext, a week to adjust coding in my old programs, and an additional week for good measure to solve problems as they arise, which makes it a project for which I'd allocate a month, before getting to the point of rebuilding the projects.

You almost certainly need the OWL code distribution from the CodeGear site, so you should get it now. But it's possible you might also need OWLNext, and it's additionally possible that the free BC5 compiler, such as if it doesn't include MAKE.EXE, doesn't provide enough tools for this job.

To repeat, this is a big job. Gather all the tools you might need and be prepared to spend a lot of time on it.

There's an OWL newsgroup at http://groups.google.com/group/borland.public.cpp.owl. It's not a very active group, but its members include the developer of OWLNext and others who have been working with OWL for years. If anyone can provide more authoritative information than I can, they would be the ones.


End of the initial series of posts
« Last Edit: March 13, 2010, 02:14:37 AM by SteveW » Report to moderator   Logged
SteveW
Administrator
Sr. Member
*****
Offline Offline

Posts: 285


WWW
« Reply #5 on: March 13, 2010, 02:55:00 AM »

I'll post some tips and tricks as I run across them.

There are a few simple replacements that can be done with #defines or typedefs or with search and replace in the code:

true and false are now keywords, and bool is now a real data type, so BOOL is not needed:

#define TRUE   (true)
#define FALSE   (false)
#define GetItemsInContainer()   size()
typedef   bool   BOOL;      

Borland C++Visual C++ equivalent
complex(x,y)complex<double>(x,y)  [it's a template class usable with different types]
constreamuse Console:: to set the attributes, then use ordinary cout << to send the output.
string::contains()(my function) stringcontains(searchin,tofind). The other "my functions" below are on the same page.
string::to_upper()(my function) toupper(s)
string::to_lower()(my function) tolower(s)
string::prepend()(my function) string& prepend(string& s, string& prefix)
TArrayAsVectorvector
(array member fn) Add(push_back(
Destroy(n)erase(n)
Flush()clear()
AddAt(insert(
TIArrayAsVectorvector<object*>. TIArray is obsolete except in unusual circumstances, because it is no longer necessary to keep total array size < 64k (1 data segment). If you use it, there is no mechanism to auto-delete members when you Flush (clear) the array. You must do it manually.
Stopwatch (my simple class)Stopwatch (.NET class)
« Last Edit: April 06, 2012, 04:29:54 AM by SteveW » Report to moderator   Logged
SteveW
Administrator
Sr. Member
*****
Offline Offline

Posts: 285


WWW
« Reply #6 on: April 06, 2012, 04:32:32 AM »

Some additional suggestions for the conversion process:

When rewriting a function call or a piece of code to newer methods, search all your source files for similar code to see if you can do all the conversions in just one or a few operations. This can be even more efficient if your editor supports regular expression search and replace in multiple files at once. Be careful with regex search/replace. A mistake can make a mess quickly, so make frequent backups that you can revert to.

If you can use .NET in your new project, it's a huge library that seems to have about everything under the sun, and all its documentation is online, so web searches are a good way to find replacements for old methods when you're not exactly sure what it is you're looking for. Search for what you want to do, along with the keyword ".NET".
Report to moderator   Logged
Pages: 1   Go Up
  Print  
 
Jump to:  

Yahoo! Search
Search the web Search this site
Mazeguy Smilies Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines Valid XHTML 1.0! Valid CSS!