Show Modal in Delphi

I was looking today at whether I could fix that annoying bug where a modal error message is shown, and if you switch to another application, when you switch back, the modal dialog gets “lost” behind the main window that’s now inactive, so you have to jump through alt-tab hoops to re-activate the window that you’re trying to acknowledge/close.

The first relevant post I came across on Stack Exchange basically said, newer versions of Delphi add some properties like setting the parent of a popup, to overcome this problem. If on the other hand you are using Delphi 7…

Again? Another problem that just upgrading Delphi would fix without a convoluted workaround? It’s not a trivial upgrade to make the app work on a newer version of Delphi, but I could be trading one bucket of problems for another….I just wish there was an edition of Delphi that wasn’t so expensive, or I probably would have already.

Delphi 7 for Java Programmers

Comments

Comment Style Java Delphi
// comment yes yes
/* comment */ yes no
(* comment *) no yes
{ comment } no yes

Delphi convention: (* code *) vs {Textual Comment}

Procedure vs Function
Method in Java = either “function” (if it has a return value) or “procedure” (if it has no return value) in Delphi

Overloading a procedure:
In the interface section of your unit, add “overload;” at the end of both overloaded versions of the procedure.

    procedure TranslateForm(form : TTntForm); overload;
    procedure TranslateForm(form : TForm); overload;

Exceptions

Java Delphi
Try Try
Catch Except
Finally Finally
Throw Raise

In order to have both an Except and Finally block for the same line of code, you have to nest Try blocks, like this:

Try
  Try
    causeSomeRandomException();
  except
    on E:Exception do ErrorMsg(num,'Error:',E.Message,True);
  end;
finally
  doSomeCleanup();
end;

Other suggested reading:
http://techinorg.blogspot.com/2008/09/delphi-for-java-developers.html
Comments on some of the differences the author found less enjoyable

http://www.webbasedprogramming.com/Java-Developers-Reference/ch5.htm
It’s going the other way Delphi to Java, so it’ll point out areas of difference, but not the Delphi syntax.

http://www.marcocantu.com/papers/ooplang.htm
Compares C++, Java, and Object Pascal (Delphi)’s OOP Features.