DELPHI
Ok, this page might be small, but it's a CONTENT page. You wont find any links here (Well, maybe few ;-). I will publish here any source code/articles I wrote, others wrote for me or interesting things I might find in the newsgroups. This is why it is so small. Anyway, the purpose of this page is to know where to look when I'll forget how to do it... If you can find something you can use here, great! What a coincidence.

A special thanks to everybody in the IRC channel #delphi. When I need a tip, when nothing is working, there's always somebody there to help me out. Some of the tips you can see here are taken directly from there and I will mention who helped me when this is the case. Thanks a lot. You can often find me there under the nick KDC.

NOT SO FREQUENTLY ASKED QUESTIONS

 
Q.How do I hide my application so it doesn't appear on the Taskbar?
A.Use the API function ShowWindow.

ShowWindow(Application.Handle,SW_HIDE);    // Hide the application
ShowWindow(Application.Handle,SW_RESTORE); // Bring it back

Note: You still have to set the Visible property to FALSE since it will still be visible on the screen, even if it's no longer on the taskbar.


Q.How can I call a user-defined function from one of my own function? (eg. Callback function)
A.First of all, create a new Type. This type must specify the parameters needed by the function or the procedure.

Type
  TRandomNumberProc = Procedure(Number : Integer)
;

This is called a Procedural Type. Notice that there's no procedure name in the declaration. The parameter name isn't important since the user will not see it and he will probably name it differently in his code. Then, create the procedure which will call the user-defined code.

Procedure RandomNumber(CallbackProc: TRandomNumberProc; Times: Byte);
  I : Integer;
Begin
  For I := 0 To Times Do CallbackProc(Random(100));
End;

As you can see, the procedure (or the function) passed in parameter can be used as any other procedures. To call this procedure, you would use this syntax:

RandomNumbers(@MyCustomCallbackFunction, 100);

Where MyCustomCallbackFunction is the user-defined function/procedure. The @ before the identifier makes it a pointer: it is not the entire procedure that's passed to RandomNumbers, it's only it's address in memory.
In this exemple, RandomNumbers will call MyCustomCallBackFunction 100 times, passing a random number beween 0 and 100.


Q.How do I 'execute' a document?
A.To use the 'lazy way', just use this code:

WinExec('start c:\readme.txt', SW_HIDE);

To use the 'right' way, use the API ShellExec:

ShellExec(Application.Handle, 'open', 'readme.txt', Nil, 'c:\', 0);

As you can see, both way are easy, but when I don't need feedback (ShellExec return error values), I simply use the 'lazy way'. To know if there's a program associated with an extension, look in the registery under HKEY_CLASSES_ROOT/.ext/shell/open/command.
Tip: Try executing something like 'http://www.infose.com/jerome/delphi.html'... This will start your browser and log to my page automaticly.



Wandering visitors: