Archive for the ‘code’ Category

Web Based IDE’s

Monday, March 28th, 2011

I started a computer club at my son’s middle school. One of the limitations is that no software can be installed, and there are no development tools on the computers. So I set out to find web based IDE’s where we can write and run code via the web browser. This is what I found.

W3Schools.comw3schools.com

I started with w3schools.com, which is a favorite reference site of mine that contains tutorials on pretty much every web technology imaginable, including HTML, JavaScript, SQL, CSS, PHP, XML, SOAP, etc.

For the client side technologies they have a great “try it yourself” functionality where you can enter JavaScript, etc. and have it display the output for you.

The process is to edit in the window on the left, then click the “Edit and Click Me” button to view the output on the right. There is no debugging or error reports, you just see what comes out. Makes it really hard to track down JavaScript typos.

It would appear some of w3schools content isn’t completely accurate, so use with caution.

JSFiddle.netJsfiddle.net

If you are developing with HTML/CSS & JavaScript and one of the common public frameworks then check out JSFiddle. It offers a resizable split view where you can edit your HTML, JavaScript and CSS all independently, and then see the combined result. Additionally it offers the option to save, share and reload “fiddles”.

Other nice features include:

  • Syntax highlighting
  • TidyUp code formatting
  • JSLint validation
  • Access to a wide selection of JavaScript frameworks
  • Discussion and forks of public fiddles

It is currently in Alpha with a limited number of public alpha accounts available

IDEone.comIdeone com thumb

This is an honest to goodness web based IDE and compiler. Type the code with syntax highlighting, compile it, provide input,

What is ideone?
Ideone is something more than a pastebin; it’s an online compiler and debugging tool which allows to compile and run code online in more than 40 programming languages, including Pascal.

How to use ideone?
Choose a programming language, enter your source code and input data into text boxes. Then check or uncheck run code (whether to execute your program) and private (whether not to list your code in the recent codes page) checkboxes, click the submit button and watch your snippet being executed.

jsbin.com

Jsbin com thumb

JS Bin is an open source collaborative JavaScript debugging tool.
Similar it offers HTML and JavaScript editing and previewing. It has a nice and clean user interface and also includes common JavaScript frameworks.

Error checking is provided by the JSHint project. Like JSLint with the addition of an API.

JSBin is completely open source, so you can download it and implement it on your own server.

Snipt.netSnipt.net

Snipt is your collection of frequently used commands or code snippets.

Because even Subversion gurus forget the ’svn merge’ syntax sometimes.

It’s good for storing small pieces of code or commands that you use rather frequently, and will probably forget.

Not really an IDE. No running or debugging. It will syntax highlight the code you upload though.

pastie.orgPastie org thumb

Pastie is a lot like Snipit. You can paste in bits of code and it will provide syntax highlighting and the ability to share it with others.

Pastie syntax highlights a number of different languages, but offers no execution, debugging, etc. Useful for sharing code. You can also search, but it is a plain text search and you don’t specific which language you are searching for, nor is there any useful meta information like description, title, etc.

A few others that I didn’t look to closely at include:

  • csdesk.com – Similar to jsbin and jsfiddle, except focused on HTML and CSS.
  • Cloud9IDE.com – JavaScript focused. Requires a sign up for a 30 day trial.
  • CodeRun.com- I had high hopes, but it didn’t work in most browsers I tested it in. This one supports development in Silverlight, C#, PHP, ASP.NET and a number of other technologies, with syntax highlighting, debugging, etc. Will keep my eye on this one.

Order of Enum in Case Statement

Saturday, July 12th, 2008

A while back my manager asked me if the order of the enums in a Delphi case statement changed performance: i.e. Enums in order being faster then those not.  I was pretty sure it didn’t, but thought it was worth checking out.  Time for a test application and some disassembly . . .

(more…)

BITS TLB and Headers

Tuesday, March 18th, 2008

If you want to program with Microsoft’s Background Intelligent Transfer Service (BITS) then you will need the TLB or header files. These can be generated from the IDL files that come with the Windows XP SP2 Platform SDK, or any of the subsequent platform SDKs, the latest being Windows SDK for Windows Server 2008 and .NET Framework 3.5. You will need MIDL to generate the needed files. It is rather a pain to download that whole SDK and then generate the useful files.To make your life easier I have generated the useful files, and also ran them through Delphi RAD Studio 2007 for Win32 to create Object Pascal wrappers for your Delphi programming pleasure. Then I wrapped it all up in a zip for easy downloading. Much quicker to download.

As a note, you do not need to deploy any of these files, or the files in the SDK with your application. You just need to ensure that the Background Transfer Service is running on the target machine.

For more information, I have created a hub page on Advanced Downloads with Delphi that I will update with more information as I gather it.

Enjoy!

[Download C, TBL, H, PAS archive]

Technorati Tags: , , , , ,

Advanced Downloads Page

Saturday, January 26th, 2008

I’ve compiled all my Advanced Downloads links into a single page to make it easy to find for anyone who was in the Seattle Code Camp session on Advanced Downloads.

Get Current Process Memory

Thursday, December 27th, 2007

Want to know how much memory your program is using? This Delphi function will do the trick.

uses psAPI;
{...}
function CurrentProcessMemory: Cardinal;
var
  MemCounters: TProcessMemoryCounters;
begin
  MemCounters.cb := SizeOf(MemCounters);
  if GetProcessMemoryInfo(GetCurrentProcess,
      @MemCounters,
      SizeOf(MemCounters)) then
    Result := MemCounters.WorkingSetSize
  else
    RaiseLastOSError;
end;

Update: Thanks to Andreas for a heap free (no GetMem / FreeMem) method of doing this (via his comment!)

Not sure where I got the basics of this, but I added some better error handling to it and made it a function. WorkingSetSize is the amount of memory currently used. You can use similar code to get other values for the current process (or any process). You will need to include psAPI in your uses statement.

The PROCESS_MEMORY_COUNTERS record includes:

  • PageFaultCount
  • PeakWorkingSetSize
  • WorkingSetSize
  • QuotaPeakPagedPoolUsage
  • QuotaPagedPoolUsage
  • QuotaPeakNonPagedPoolUsage
  • QuotaNonPagedPoolUsage
  • PagefileUsage
  • PeakPagefileUsage

You can find all of these values in Task Manager or Process Explorer.

Maybe this would be a good task for one of Delphi’s new records that include methods. . . .

It would appear

List of 3rd Party Components for Delphi 2007

Friday, December 7th, 2007

My thanks to Andreano Lanusse, the Product Line Manager for Latin America at CodeGear, who just posted a list of 3rd Party Components for Delphi 2007. This is a great resource. Andreano is open to suggestions and feedback on his list too and has provided his email address for everyone.

This has long been one of the strengths of Delphi – the strong collection of 3rd party components. 3rd party component development was of course fostered by the fact that Delphi came with full source for the VCL and RTL. A move the Microsoft if finally duplicating in releasing the source for the .NET framework. Although unlike Delphi, Microsoft will not allow you to modify and recompile the framework in your applications. With Delphi you can tweak the VCL and recompile it (not a trivial task, but allowable and possible) for your applications. Granted doing so makes moving to new versions of Delphi a little more tricky, and you cannot redistribute the modified source.

BTW, notice the link to my TurboPower page on line 27.

CodeRage II is a Success

Friday, November 30th, 2007

Wow, what a week. CodeRage II went great. A lot of good content and I enjoyed presenting my sessions. You can get the code, links, etc. from them here:

They all went really well I thought. Unfortunately I pushed the deadline back too far on Delphi Robot Rage and my JIT Presentation didn’t happen on time. Sorry to everyone about that.

Check back often for updates (seriously), or let me know if I missed something you are looking for from my sessions.

Thanks!

Crashing Like VB

Wednesday, November 28th, 2007

I always thought Delphi’s global exception handler was a great feature. It allows your program to continue after an otherwise unhandled exception would have caused it to terminate. Typically in a serious application you would assign your own global exception handler, or used one of the great 3rd part exception handlers like madExcept or Exceptional Magic (I love that name!) They both provide a nice dialog, stack trace, logging and reporting.

Well it turns out that if you want to be Microsoft Windows Vista Logo certified, then you need to crash your application on certain exceptions.

Applications must handle only exceptions that are known and expected, and Windows Error Reporting must not be disabled. If a fault (such as an Access Violation) is injected into an application, the application must allow Windows Error Reporting to report this crash. (from requirement 3.2 Resilient Software: Eliminate Application Failures)

Microsoft’s rational for this requirement is the ISV will receive the error report Microsoft collects for them. I guess most software developers don’t have access to tools like we do in Delphi to catch exceptions and log them for us.

So short of tossing out the Forms unit and writing everything from scratch, how can you get around the usefulness of the global exception handler.

My first thought was to create a custome application exception handler by placing a TApplicationEvents on your main form and assigning the OnException event. In the event include the line

  raise e;

This will pass an exception up to the operating system and terminate your application, at least when I tested it in Delphi 2007. When I tried it in Delphi 7, it didn’t work right.

A more elegant and involved solution:

First you need a couple global variables:

var
  GlobalExcept: Exception;
  GlobalExceptAddr: Pointer;

And a global exception handler:

procedure TForm1.ApplicationException(Sender: TObject; E: Exception);
begin
  if E is EAccessViolation then
  begin
    // Keep the exception object from being destroyed!
    AcquireExceptionObject;
    GlobalExcept := e;
    GlobalExceptAddr := ExceptAddr;
    Application.Terminate;
  end;
end;

The rest of the magic happens in the project file (DPR)

begin
  GlobalExcept := nil;
  GlobalExceptAddr := nil;
  try
    Application.Initialize;
    Application.CreateForm(TForm1, Form1);
  Application.Run;
  finally
    if Assigned( GlobalExcept ) then
    begin
      raise GlobalExcept at GlobalExceptAddr;
    end;
  end;
end.

And you can [download the code].

Thanks to Jeremi Reda for asking this question in borland.public.delphi.non-technical.

I didn’t cover this in my CodeRage II session on Exceptional Exceptions, but there is a lot of other cool stuff, like AcquireExceptionObject!

D-Robots and Delphi Robot Rage

Tuesday, November 20th, 2007

The last session of CodeRage ][ (now FREE!) is the Delphi Robot Rage. This is your opportunity to show off your amazing Delphi programming skills. Download D-Robots and build your robot to compete in a Death Match on the Light Plaza map against one or more robots created by other participants. There will be amazing prizes (undisclosed as of yet), but of course the best prize will be having your amazing programming skills shown off to the world.

Requirements:

  1. Robot must have unsecured source (no password, or password must be provided), although the source will not be revealed until after the challenge is completed.
  2. If a unique skin is not used for your robot, then a new skin may be assigned to your robot for visual identification.
  3. Competition is open to everyone. No purchase necessary. Not required to be in attendance at CodeRage II to enter or win, although that is the best way to see the action!
  4. Email your robot to me (delphirobotrage@davinciunltd.com), and I will reply with acknowledgment. If I don’t reply, I didn’t receive it.

Deadline for submissions: November 26th, 2007 – midnight Pacific Time

Notice: There is an incompatibility between D-Robots and some video drivers (maybe just ATI). No known work around. It does work in a virtual machine, but your frame rate will be very poor.

If you submit your robot early enough, you might get some feedback from a practice round.

Short intro video online & Partial list of prizes.

Questions? Comments?

Just Talking to My Self

Wednesday, November 7th, 2007

There is something rather trippy about debugging a server that opens a socket and talks to itself.  Have to pay really close attention or Delphi will trace back into the server again, and all of a sudden you are someplace entirely different in the application.  Of course if you have a break point that gets triggered by the connection you had better disable it before you connect again.

Now to figure out if the server can get the information it needs from itself without going through a socket connection to itself.  I can see that being a bad scenario if it keeps opening new sockets back to itself again. . . .

Almost as much  fun as leaving comments and ping backs on your own blog.