I need to add some script support for an old w32 MFC application. It should be possible for user to enter a custom formulas for further calculation. It should be very simple edit control with syntax highlights and error messaging. Do any solutions for lua(activx or dll) which may be embedded to my application exist?
Scintilla includes a Lua lexer and provides syntax highlighting and more. Error messages can be displayed as annotations.
Related
I have deveoped a custom file type, together with a custom editor (basically a tree with several data pages attached and a few extra buttons). OK, I can run it stand alone and that is fine, and even add it to the tools menu, but I would like to integrate it into the Delphi IDE so that my custom editor (or a similar new version) appears in the IDE, rather like a DFM file has a custom editor. I can find references to most extensions in the Delphi IDE, but not this one. Any guiding hands? Note that this is not a property or component editor (the file type has nothing to do with either of these) nor is it simply syntax highlighting of a text file.
AFAIK it currently isn't possible to reliably integrate a custom editor into the Delphi IDE. The required API simply isn't there. See QC89028 Custom Module support.
During the Delphi 2010 and XE betas I spent most my spare time trying to get a resource editor integrated. Although the effort had the official blessing of Embarcadero and got some, half hearted, support from the IDE engineer, I was never able to get them to deliver on their promises and surface the module API. I eventually abandoned the project.
Update: I've now checked my old correspondence regarding this and it turns out part of the problem was that IOTAModuleCreator (used to implement File|New for custom file types) and IOTAEditorContent (used to transfer data to/from the custom module) only supports text data. Binary data gets mangled.
You can probably do this via an IDE plugin that uses the ToolsAPI (see ToolsAPI.pas in the IDE's source folder (e.g. Program Files (x86)\Embarcadero\Studio\source\ToolsAPI\ToolsAPI.pas.)
For information on writing a plugin in general, see David G Hoyle's excellent blog. Once you know the basics - i.e., write a 'wizard' and get it to do something - you will need to work on integrating your editor.
I have never done this, and so I can't guarantee it is possible. However, some interfaces that look worth investigating and implementing are INTACustomEditorView, which represents a 'view' (file tab when that file is open - think the code editor, Welcome view, type library editor, etc) and IOTAEditorViewServices, to register your custom view. I do not know how you associate a view type with a file type, sorry - possibly something to do with the personality interfaces. You might also be interested in INTACustomEditorSubView which is what creates a tab on the bottom of a file.
Good luck, and if you find a solution please write here so that other people can learn too!
I am interested in the ability to have F# scripting within my app.
Having something like tryfsharp.org would be great, specifically the Intellisense capability. Is any of this available on Github somewhere? How does this work?
Short answer
The code used for the first cut of TryFSharp with F# 2, which includes Intellisense support, is available as a code drop. As an example Rob Pickering built an online editor for Undertone with it. I suspect the code used on the current TryFSharp site which uses F# 3 will appear in time.
TryFSharp uses Silverlight to host the F# compiler in the client's browser (F# is written in F#). It is also possible to call an instance of the F# compiler running on the server from the browser on demand, which is an approach taken by TryFs.Net and Pit.
Longer answer
There are two sides to scripting:
Editing
Execution
F# already supports editing and execution of (.fsx) script files via F# Interactive.
Editing F# Code
There's no shortage of external editors for F# code:
Visual Studio
SharpDevelop
Xamarin Studio
Emacs
Vim
TryFSharp
F# Notebook
The editor support for Xamarin Studio, Emacs and Vim is based on the open source F# Bindings project, which provides code completion.
SharpDevelop uses the open source AvalonEdit and includes syntax highlighting for F#. You can use AvalonEdit in your own projects, for example the open source Refunctor project uses it to provide F# editing inside Reflector.
There are also a couple of new editors for F# on the horizon:
Cloud Sharper - web based F# IDE
Tsumani IDE - embedded editor for Excel, Hadoop, etc.
AvalonEdit is a good place to start for a desktop based embedded editor. Once you've chosen an editor environment then you need to choose between simple syntax highlighting or more advanced integration using F# Bindings. If you suspect people will use an external editor then syntax highlighting may be sufficient.
Bring your own editor is probably the easiest place to start which just leaves execution.
Executing F# Code
Options for executing F# code:
F# CodeDOM from the F# PowerPack
F# Compiler via the F# compiler code drop or invoking fsi.exe
Compiling a snippet with the F# CodeDOM:
open Microsoft.FSharp.Compiler.CodeDom
open System.CodeDom.Compiler
let compile snippet =
use provider = new FSharpCodeProvider()
let options = CompilerParameters(GenerateInMemory=true)
provider.CompileAssemblyFromSource(options, [|snippet|])
let snippet = """
module Snippet
let x = 1
"""
let results = compile snippet
At the moment, whenever I need a custom dialog, however simple, I use Delphi's form designer to create a new dialog form. The form is then wrapped in an easy to use ShowMessage() type function.
In some situations it would be easier if forms could be created at run-time from a script. The script would detail all form components and their properties, much like Delphi's .DFM files.
Creating GUIs from scripts could be useful in other situations as well. For example, a GUI of a mini application could be embedded into the window of an existing application. Or the GUI script could be modified at run-time to create GUI variations.
I could create something to do this myself, but I assume other people have already tackled this problem. However I can't find anything using google. Is there anything currently available offering this kind of functionality? (Free or otherwise) Or does it already exist in Delphi?
Check out some of the scripting solutions for Delphi. For example, the TMS Scripting Studio, dwScript, RemObject's, FastScript, etc. I believe some of them are able to use DFM's for this purpose.
http://www.torry.net/pages.php?id=280 Delphin v.1.21, it can process DFM files, maybe you just want the DFM to code converter.
You might try XI Library (commercial): http://xilib.com/
I have never used it, it's just something sitting in my bookmarks, but it looks like it fits the bill. Not a scripting engine, more of a way to define dialog boxes via XML. There's sample XML code right on the front page, just click "Show the example".
I have a quite old Windows application (1998) which is no longer maintained by the author and I don't have its source code. This application in one of its windows has a dropdown list widget where the user can choose one of the 4 predefined values (numbers). I need to add new predefined values there or change the widget to something that lets me introduce any value (some edit field or editable combobox).
Some other data about the application:
Probably written using some Borland tools, I guess it uses BDE and Paradox as its database.
There is a file with .mme extension in the directory. I unpacked it and it contains 5 files: .data, .rdata, .rsrc, .sdata, .text. I viewed them in a hex editor and they contain some text data but I don't know how to look for those predefined values. Since they are numbers it's probable that I will find just some other numbers.
I tried using RedEdit and XN Resource Editor but they show only the icon and version info.
I know my question is kind of vague, but if I don't find any solution to this I will have to rewrite the whole program, so I'm asking just in case there is a solution.
It might be possible to write another app that looks for this program, gets a handle to the window owning the drop-down box (if t's a native windows component), and then gets a handle to the drop-down box and use the Windows SendMessage API to manipulate the contents of the drop-down box.
http://msdn.microsoft.com/en-us/library/ms632595(v=VS.85).aspx
http://msdn.microsoft.com/en-us/library/ms644950(v=vs.85).aspx
It might require so much effort that it may be better to just rewrite the app!
If it is written with Borland tools, you can probably find out which one by searching the EXE for the string "Borland" - there should be a copyright string somewhere.
Once you know, find someone with Borland tools experience and have her find out if those numbers in the drop-down list happen to come out of a database table. If they do, try modifying that table, if not, rewrite the app :)
I am currently working with 'inherited' code that has (scattered randomly throughout) a whole bunch of conditional compiler directives based on the version of Delphi, going back to Delphi 2 . From now on, all development will be with Delphi 2009 or future. Is there a tool in Delphi 2009 , or a plugin, that will automatically remove compiler conditional code segments based on a specified 'minimum' version?
I highly recommend the Delphi Inspiration Pascal Preprocessor (DIPP)
This can do a number of things with a source file in addition to removing conditional defines, including the "inlining" of include files and removing comments (all of course highly configurable and controllable by options supplied to the processor).
The conditional defines functionality is especially useful as you can either have all such conditionals simply removed or provide a set of DEFINE's that you wish to apply. DIPP will then emit a source file that reflects how it would appear to the compiler with those symbols DEFINED, but without the conditional directives themselves.
So in your case you would simply defined the symbols appropriate to your "baseline" Delphi version.
You should give JEDI PreProcessor (Pascal PreProcessor) in the JCL a try.
In the trunk in our SVN the source can be found in the dir jcl/devtools/jpp and in our latest release (2.1) zip-file the jpp.exe can be found in the dir devtools.
I don't know of such a tool but it should be relatively straight-forward to write it.
Loop through all files in the directory using FindFirst and FindNext
Use TStringList.LoadFromFile to read all pas files.
Loop through the strings and look for {$IfDef} directives. If the version specified in the conditional section is older than D2009 remove all text until the {$EndIf}.
Use TStringList.SaveToFile to write the modified file to disk.
My advice would be to ONLY change code you completely manage. If however you are also going to modify existing 3rd party code, then I suggest you go through each IFDEF defined for validation. Some vendors do not use the standard IFDEF VERxxx calls, but create their own which might be called something like VER70UP or such. The most common place for this would be in include files, so look for a {$I ???.INC} file near the beginning of each file, then analyze this for what is being used and how.
The other reason to analyze each $DEFINE/$UNDEF is the fact that a version specific one might turn on a new define that your previously not checking...one that ultimately leads into dead code.
Use GExperts, you can use both GrepSearch or GrepRegularExpressions to search in your code and then use the Replace tool in the GrepResults to remove whatever you need.
You can do a search and replace
operation on all of the matches in the
list or only the selected file/match.
When you choose one of those options,
a dialog appears prompting for the
string to use in place of the matched
text. Note that forms that are
currently open can not have their text
replaced, due to limitations in the
IDE. Please close all forms before
trying to replace text in them.