I.T. Discussion Community!
-Collapse +Expand
Prism
Search Prism Group:

Advanced
-Collapse +Expand Prism To/From
To/FromCODEGuides
-Collapse +Expand Prism Study Test
PRESTWOODCERTIFIED
-Collapse +Expand Prism Store
PRESTWOODSTORE

Prestwood eMagazine

February Edition
Subscribe now! It's Free!
Enter your email:

   ► KBProgrammingDelphi PrismTool Basics   Print This     
  From the January 2016 Issue of Prestwood eMag
 
Prism Tool Basics:
Share Code with Delphi and Prism
 
Posted 10 years ago on 2/22/2009
Prism Q&A Flashcard:
 A flashcard from our Prism Flashcards Library
 A FAQ from our Prism FAQ Page

KB101928



Question:

Can I share code between a Delphi and a Dephi Prism project? I want to have a single source Win32 and .Net application.


Answer:

No, not really. Because both are Object Pascal based, you could share routines but there are enough syntax differences that make sharing large amounts of code difficult.

Use Oxidizer to help port your Win32 Delphi application to a .Net Prism application.

You can also try out ShineOn which is an implementation of the Delphi for Win32 RTL.


Delphi for .Net and Single Source Win32/.Net Apps

One of the strong selling points for Delphi for .Net (part of Delphi 8, 2005, and 2006) were the features that allowed you to have a single source application for both native code Win32 and .Net. However, the features were rarely used. Most users wrote either a native code Win32 application or a .Net application. Most users felt there was no need for both. It's true that you could write a .Net application for Mac or Linux that targeted Mono at the same time you targeted Win32. However, the reality was that those features were not highly sought.

If you had a Delphi application and a need to convert to .Net, the VCL.Net and RTL.Net made a lot of sense and made porting your application a minimal effort project. For Prism (the replacement for Delphi for .Net), the Oxidizer along with ShineOn are efforts to reproduce that minimal effort required for porting.


Comments

1 Comments.
Share a thought or comment...
Comment 1 of 2

Heres my approach, I dont say its the right approach or the best approach, but its what Ive done. 

I went through my code and found all the instances where the syntax to do something in PRISM is different from Delphi syntax (e.g. file manipulation: reading, writing, opening or closing a file).  Ignoring syntax incompatibility for a moment, I duplicated the code segment using PRISM syntax (i.e. using all the PRISM/.NET methods that are illegal in Delphi).  I incorporated a hard-coded boolean variable to act as a switch between Delphi code block and the PRISM code block. 

To get rid of the PRISM-syntax errors that arise when the code is compiled in Delphi, I create dummy methods that have the same name as the .NET methods, but theyre just empty, there is virtually no code in them; they are just there to suppress compiler errors. 

It doesnt matter if theyre empty because they will never be called if the software is compiled using Delphi... because of the switch mentioned above. 

Then I did the same thing defining methods with Delphi names (creating a bunch of empty methods), but they are all commented out. 

Result: the software compiles under Delphi and runs normally, since the PRISM code blocks are never called. 

To compile for PRISM, I do the reverse; I comment out the PRISM method set (the names match up with .NET method names), and uncomment the Delphi set.  The empty Delphi procedures are only there to stop PRISM compiler errors; the procedures are never called during execution, because the switch is set to select the PRISM code blocks, and the Delphi ones are never called. 

It doesnt work for every problem, but does for many. 

Then you can maintain two versions of your code, a Delphi one and a PRISM one, as long as you keep the dummy procedure set up to date.   I wrote a white paper about this, its here: http://skyindustries.com/Page_10.0_CIED_Video.html  (click on the PRISM-Delphi White Paper link at the top of the page, theres no way to attach a PDF to this comment). 

---
Shawn C
Posted 7 years ago

Comment 2 of 2

Shawn:

Great approach! Very similar to coding for Win32/Win64 in Delphi and other such code base compiler if defs.

Mike

Posted 7 years ago
 
Write a Comment...
...
Sign in...

If you are a member, Sign In. Or, you can Create a Free account now.


Anonymous Post (text-only, no HTML):

Enter your name and security key.

Your Name:
Security key = P1182A1
Enter key:
FAQ Contributed By Mike Prestwood:

Mike Prestwood is a drummer, an author, and creator of the PrestwoodBoards online community. He is the President & CEO of Prestwood IT Solutions. Prestwood IT provides Coding, Website, and Computer Tech services. Mike has authored 6 computer books and over 1,200 articles. As a drummer, he maintains play-drums.com and has authored 3 drum books. If you have a project you wish to discuss with Mike, you can send him a private message through his PrestwoodBoards home page or call him 9AM to 4PM PST at 916-726-5675 x205.

Visit Profile

 KB Article #101928 Counter
12169
Since 2/22/2009
-
   Contact Us!
 
PrestwoodBoards.com was developed and is maintainted by me. Do you have a question or suggestion? Do you see a problem? Contact me now. My goal is to build an ad-free and spam-free source of I.T. information with many contributers (ok to promote your website/company in your bio). Yes, my company Prestwood IT Solutions is mentioned in my bio which shows with every post, but you can contribute and promote your pet project too!

2,074 People Online Now!!  
Sign In to see who's online now!  Not a member? Join now. It's free!
Show more stats...


©1995-2019 PrestwoodBoards  [Security & Privacy]
Professional IT Services: Coding | Websites | Computer Tech