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.
Archive for the ‘Delphi’ Category
Advanced Downloads Page
Saturday, January 26th, 2008Get Current Process Memory
Thursday, December 27th, 2007Want 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
CodeRage II -> Delphi Robot Rage final standing
Sunday, December 9th, 2007The official standing of the bots was given during the live broadcast of the final session. Although if you run the bots in a new battle, chances are a different bot may win. There certainly is a bit of luck involved. Never the less, these are the official results.
- 1st Place – Brian Thoman and Codralis of WideOrbit Inc. in Lynnwood, WA
- 2nd Place – Michael Madsen and Kisai of Logos Consult in Denmark
- 3rd Place – Ken Adam and Akadamia of Akadamia Ltd in Midlothian, UK
Thanks to everyone who entered a bot! I’ll be arranging the prizes with you all shortly. Thanks to all of the prize contributors too. A special thanks to everyone at CodeGear who made CodeRage possible!
Bot profiles and other details will continue to be posted.
At this point I am not posting the last battle recording. The quality was terrible, and most everyone can run their own battle with the bots and D-Robots (possibly reaching a different outcome though. . . )
List of 3rd Party Components for Delphi 2007
Friday, December 7th, 2007My 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.
Multi-Class Class Helpers
Monday, December 3rd, 2007This is cool. I figured out a way to assign the same class helper to multiple classes in Delphi 2007. Marco Cantu asked me if I knew how to do this during CodeRage II, and then David I. mentioned that Class Helpers should be used to implement Aspect Orientated Programming (AOP), but since they don’t support assigning the same class helpers to multiple classes that wouldn’t work.
I’ll write this up later. It isn’t a best case scenario, and requires a few extra lines of code, but it accomplishes what I set out to do, and that is pretty dang cool! Hopefully later CodeGear will extend class helpers and make this and other cool stuff easier. . .
Exceptions in Constructors and Destructors
Monday, December 3rd, 2007Check out Alister Christie’s latest movie on CodeGearGuru.com. He covers the elusive Exceptions in Constructors and Destructors. Thanks Alister. That was one of the questions from my Exceptional Exceptions session that I needed to follow up on.
CodeRage II is a Success
Friday, November 30th, 2007Wow, 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, 2007I 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!
10 Top Things Added to Delphi Since Delphi 7
Monday, November 26th, 2007The session “Leveraging What You Have: 10 Top Things Added to Delphi Since Delphi 7″ by Pawel Glowacki was one I was looking forward too. The audio and video quality was a little poor, so I skipped it to watch later when I had more time. Pawel posted his list though, with a lot of details. That is probably more valuable to me then the video session. If the video was chopped up by list item so I could jump to a feature I was unfamiliar with, that would be really cool.
There are a lot of really cool enhancements since Delphi 7. I know a lot of people were holding out on Delphi 7 because it was such a solid release. Delphi 8 was .NET only, and of questionable stability. Since then each release has gotten much better. I must say, Delphi 2007 is definitely worthy of an upgrade from Delphi 7.
Attending CodeRage II
Monday, November 26th, 2007So I am breaking the cardinal rule of attending a virtual developers conference: multitasking. Sure, that is one of the advantages, but at the same time, it really detracts from how much you get from the conference if you are are tying to do your job at the same time (not to mention it detracts from your job performance). Normally I would commit some time, but we are on a serious deadline right now, so I am getting it done.
As a result I am skimming many of the sessions. I’ll catch them on replay.