Solved

Compiling stored code at runtime

Posted on 2002-03-27
15
327 Views
Last Modified: 2010-04-04
Alright, I don't know if this is possible or not. I am looking for a way to compile and run stored code at runtime on a machine that does not have delphi installed on it.  

What I would like, is for some procedures to be stored in a database and/or binary file. The main program would access and pull in this data, compile it, and run it, all at runtime.

Any thoughts?

chmod101
0
Comment
Question by:chmod101
  • 6
  • 3
  • 2
  • +4
15 Comments
 
LVL 6

Accepted Solution

by:
edey earned 66 total points
Comment Utility
mmm, rather then compiling it, why not use a scripting engine? The all you have to do is store the scripts (as plain text) in your db

GL
Mike
0
 
LVL 6

Expert Comment

by:edey
Comment Utility
Hmm, I guess if you're really set on using compiled object pascal you still couldn't use delphi as you don't have a licence to redistribute the compiler. There is a list of free pascal compiler (some of which you can distribute) here : http://www.thefreecountry.com/developercity/pascal.shtml

GL
Mike
0
 

Author Comment

by:chmod101
Comment Utility
yeah, I figured that there would probably be some  problems with licensing, even if it were possible to do it.

As for the scripting, that was my next option if I couldnt do it this way.  I guess I was just trying to avoid having to write the interpreter for the scripting, unless you know some pre-written scripting code for pascal interpreting.

Thanks for the help.
chmod101
0
 
LVL 6

Expert Comment

by:edey
Comment Utility
I don't off hand, but virtually any computer with windows on it will have MS's scripting engine on it. It might just be easier to  learn to do the bits which have to be scripted in jscript. It might not be as much as you think as the engine allows pretty easy access to activex automation objects.

GL
Mike
0
 
LVL 45

Expert Comment

by:aikimark
Comment Utility
or you could produce assembler code and compile it on the fly.

or you could compile the assembler program and copy its bytes into memory and execute it.

or you could write in Java, which is pretty universal.  Just make sure you distribute the JVM with your app.

Depending on the target OS, you might take advantage of native scripting language support.
0
 
LVL 14

Expert Comment

by:DragonSlayer
Comment Utility
or if you want scripting but still prefers Pascal, check out Innerfuse Pascal Script at http://www.carlo-kok.com/
0
 
LVL 5

Expert Comment

by:Gwena
Comment Utility
Are you trying to make a simple program generator?

Like maybe a delphi program that lets the user select certain things it would like the program to do... such as creating a custom file patcher... and then your program either modifies itself at runtime or creates another exe that performs as the user wishes?

If you want to create an exe generator that has narrow scope then it's easy... but a general purpose exe generator that could create anything that Delphi does is going to be HARD... just tell them to download the free D6-personal edition in that case.

If you do want to make a simple exe generator then I can send you a demo of how modify an exe at runtime or create a new modified exe... it's pretty easy stuff.

Oh... the idea of compiling asm code at runtime is do-able... although it requires an in depth knowledge of assembler... or just store a copy of nasm inside your exe and pop it out to disk and have it compile the code... then delete the nasm.exe file... hey..it's a bit Rube Goldberg'ish but it would work :-)
0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 6

Expert Comment

by:edey
Comment Utility
Hmmm, I think this is one of those "There's a thousand solutions, could you define the problem a little?" sort of problems. If we knew more about why you need to ship uncompiled code we might be able to give more specific, more usefull sugestions

GL
Mike
0
 
LVL 9

Expert Comment

by:ITugay
Comment Utility
Hi all,
it's a good question!

btw, if part of code should be compilled at runtime for prepare some report, then there is a good RBuilder that allow you to write pascal code and compile it at runtime. Also it able to access object's property and make some operations with it.

Of course it's not free :-(

-----
Igor
0
 
LVL 3

Expert Comment

by:rondi
Comment Utility
Hey, have you guys heard of Delphi Web Script ?
It's this cool object oriented Active-X script language based on object pascal. It's accessible from web pages,
apps, wherever. It's free and open source too.

I downloaded it, but haven't had the time to try it
out.

Check out http://www.dwscript.com
0
 

Author Comment

by:chmod101
Comment Utility
Thanks for all of the suggestions, guys.  Here is  a more in-depth description of the problem:

The program is being developed as part of a research project at a university.  It is a piece of homework software for students to use. However, it is a modular package that allows itself to be used with different textbooks.  The problem, is that the people who worked on this before me didn't give much thought to the EASE of switching from module to module (say from a calculus homework program to a statistics homework program).

The way it is set up, is that the code that is run for each problem is its own procedure,and there are hundreds of them for a given textbook.  Now, what I am trying to do is to decrease the amount of interaction that a person makes with the main body of code in order to program a problem for a new module of the program.  My hope is to completely eliminate any changes that have to be made directly to the code, thus increasing the modularity of the software package.  So, if I could store the code for the problems in a text file, binary file, database, whatever, and either compile or interpret it at runtime, then I could effectivle black-box the main body of code.

Now, my idea, and this may be a little odd, was to use an XML-like document to script out each problem.  Something like this:

<problem>
 chapter = 2
 section = 1
 problem = 2
</problem>
<variables>
 x : integer
 y : integer
 z : integer
</variables>
<Ranges>
 x : 1 to 5
 y : 10 to 20
</Ranges>
<code>
 z = x + y
</code>
<END>

Of course, in order for this to work,  I would have to write a procedure to interpret this XML-like scripting, and that procedure would have to be able to create all of the variables dynamically, randomize the values of the variables within the ranges provided, and then perform any mathematical operation called for by the <code>...</code> section. I can do this, but providing code to interpret any/all mathematical possiblities would take a bit of work.

So, those of you who have suggested different scripting languages, how can I use something is Pascal Script or some other scripting language to do this? I have done extensive work with JScript, so I guess my question is how do I incorporate a text file containing Pascal Script, JScript, or some other scripting language into a Delphi project so that it is interpreted and executed.

Also, anyhing that requires an ActiveX component, while not completely taboo, is less than desirable, since that component would then have to be installed on any machine using this program.

Again, thanks for your help.
chmod101
0
 
LVL 6

Expert Comment

by:edey
Comment Utility
In this case Gwena's sugestion (bundling the personal edition, prob doable - it's already free, but you'd have to talk to Borland) makes a lot of sense.

GL
Mike
0
 
LVL 5

Expert Comment

by:Gwena
Comment Utility
Hi chmod101 :-)

I see now what you want to do.... it would take some work but I think you could do this by storing the descriptions of the new questions as text at the end of the exe.. then at runtime have some of your code that reads the text and parses it out and creates the actual question that the user sees... the logic code to handle the questions might be quite involved... like a mini Mathematica.. but you can do it.

As I said it is easy to make a delphi program that can alter itself at runtime by adding data to it's end... all you need to do is to write the code to interpret the new Q's.
 
I like to write programs that are totally self contained... no ini files, no registry useage, no dll's unless they are bundled into the exe and can be ejected if needed at runtime... I don't like install programs that leave traces behind either... and uninstalling your app should mean just deleting the one single exe file... and where possible all new data should be added to the exe itself so that it is hard to lose track of... of course this last is not always possible because of data size.

I can write you a simple demo that has a button and an edit box... type a string into the edit box and press the button... and poof! the exe now has the string appended to the end of it's file on disk...Or just make a fill-in-the-blanks form for creating new questions and it will look really nice. if you can figure out how to use the string to represent your new question then you will have all that you need... and the whole thing will be in one exe file... nice and tidy :-)
0
 
LVL 6

Expert Comment

by:edey
Comment Utility
Hey, just wondering how you were making out.

GL
Mike
0
 

Author Comment

by:chmod101
Comment Utility
sorry about the pause in correspondance. Another project came up that I had to write a paper for.  I have pretty much decided that I will use my original idea or scripting the problems and writing an interpreter to interpret the code at runtime.  

Since mike's (edey) first comment was closest to this, I will give him the points.

Thanks for all of the help, everyone.
chmod101
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now