<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>solutions.hans-eric.com &#187; Delphi</title>
	<atom:link href="http://solutions.hans-eric.com/category/delphi/feed" rel="self" type="application/rss+xml" />
	<link>http://solutions.hans-eric.com</link>
	<description>Hans-Eric Grönlund's Log of Solutions to Technical Problems</description>
	<lastBuildDate>Fri, 23 Apr 2010 07:39:00 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Dynamic Updating of Action Visibilities</title>
		<link>http://solutions.hans-eric.com/dynamic-updating-of-action-visibilities</link>
		<comments>http://solutions.hans-eric.com/dynamic-updating-of-action-visibilities#comments</comments>
		<pubDate>Tue, 01 Sep 2009 16:38:25 +0000</pubDate>
		<dc:creator>Hans-Eric</dc:creator>
				<category><![CDATA[Delphi]]></category>
		<category><![CDATA[Updating TAction.Visible]]></category>

		<guid isPermaLink="false">http://solutions.hans-eric.com/?p=18</guid>
		<description><![CDATA[Problem: You want to change an action&#8217;s visible property and does so in its OnUpdate event handler, but it doesn&#8217;t seem to work. Once an action is hidden it can&#8217;t seem to become visible again.   Solution: By design Delphi won&#8217;t invoke OnUpdate event handlers for actions that have their Visible property set to false. [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Problem:</strong> You want to change an action&#8217;s visible property and does so in its OnUpdate event handler, but it doesn&#8217;t seem to work. Once an action is hidden it can&#8217;t seem to become visible again.   <strong>Solution:</strong> By design Delphi won&#8217;t invoke OnUpdate event handlers for actions that have their Visible property set to false. Instead, one has to override the form&#8217;s UpdateActions method tod do the dynamic checking and setting of Visibility.</p>
<pre><code>type
  TMainForm = class(TForm)
  ...
  protected
  ...
    procedure TMainForm.UpdateActions; override;
  ...
  end;

...

procedure TMainForm.UpdateActions;
begin
  inherited;
  // Those actions are updating their visible
  // properties and must therefore be updated
  // here and not in their respective update
  // event handlers. This is due to the fact
  // that invisible actions are not concidered
  // by the inherited UpdateActions loop.
  // This is by design according to CodeGear.

  CancelAction.Visible := IsRunning;
  StartAction.Visible := not CancelAction.Visible;
end;
</code></pre>
<p>More information can be found on the Delphi forum, here:  <a href="https://forums.embarcadero.com/thread.jspa?threadID=18206&amp;tstart=90">https://forums.embarcadero.com/thread.jspa?threadID=18206&amp;tstart=90</a></p>
]]></content:encoded>
			<wfw:commentRss>http://solutions.hans-eric.com/dynamic-updating-of-action-visibilities/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How To Create a Tray Icon Controlled Application in Delphi</title>
		<link>http://solutions.hans-eric.com/how-to-create-a-tray-icon-controlled-application-in-delphi</link>
		<comments>http://solutions.hans-eric.com/how-to-create-a-tray-icon-controlled-application-in-delphi#comments</comments>
		<pubDate>Fri, 07 Aug 2009 08:46:02 +0000</pubDate>
		<dc:creator>Hans-Eric</dc:creator>
				<category><![CDATA[Delphi]]></category>
		<category><![CDATA[TTrayIcon]]></category>

		<guid isPermaLink="false">http://solutions.hans-eric.com/?p=9</guid>
		<description><![CDATA[Problem:
We want to create a System Tray Icon featured application that doesn&#8217;t shut down when the user closes the main window. Instead, the form simply hides and is reactivated when the user clicks the associated tray icon.
Solution:
Tested in Delphi 2009.
1. Hide the main form.
Since closing the main form automatically terminates the application we need to [...]]]></description>
			<content:encoded><![CDATA[<h4>Problem:</h4>
<p>We want to create a System Tray Icon featured application that doesn&#8217;t shut down when the user closes the main window. Instead, the form simply hides and is reactivated when the user clicks the associated tray icon.</p>
<h4>Solution:</h4>
<p>Tested in Delphi 2009.</p>
<p>1. Hide the main form.</p>
<p>Since closing the main form automatically terminates the application we need to hide it from the user. This is done by setting Application.ShowMainForm to False in the project settings.</p>
<pre><code>Application.Initialize;
<strong>Application.ShowMainForm := False;</strong>
Application.MainFormOnTaskbar := True;
:
Application.Run;
</code></pre>
<p>2. Add a TTrayIcon to Main Form</p>
<p>Set the Icon property and add an OnClick event handler that displays your real main form (the one that the user will see).</p>
<pre><code>procedure TMainForm.TrayIcon1Click(Sender: TObject);
begin
  MyOtherForm.Show;
end;
</code></pre>
<p>3. Drop a popup menu on the main form and connect it to the tray icon.</p>
<p>Add a close menu item that calls Application.Terminate to kill the application.</p>
<pre><code>procedure TMainForm.Close1Click(Sender: TObject);
begin
  Application.Terminate;
end;
</code></pre>
<p>4. Make the real main form show on start of application</p>
<p>Simply add a OnCreate event handler to the form and invoke Show.</p>
<p>procedure TMyOtherForm.FormCreate(Sender: TObject);<br />
begin<br />
Show;<br />
end;</p>
<p>That&#8217;s it!</p>
<p><strong>Alternative solution 1. </strong></p>
<p><strong>OBSERVE! This solution has the rather big flaw that it stops the computer from shutting down.<br />
</strong></p>
<p>1. Intercept the automatic termination mechanism when the main form is closing</p>
<pre><code>procedure TMainForm.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
  // Minimize application instead of closing
  CanClose := False;
  Application.Minimize;
  // Remove the main form from the Task bar
  Self.Hide;
end;
</code></pre>
<p>2. Clicking on the tray icon restores the application</p>
<pre><code>procedure TMainForm.TrayIcon1Click(Sender: TObject);
begin
  // Restore application from minimized state
  Application.Restore;
  Application.BringToFront;
  // We must invoke Show on the main form, otherwise
  // it won't be able to minimize properly a second time
  // Tested on D2009 Upd 3, and Windows XP
  Self.Show;
end;
</code></pre>
<p>3. Add a popup menu with a close action to the tray icon, and use Application.Terminate in the event handler to kill the application</p>
<pre><code>procedure TMainForm.CloseActionExecute(Sender: TObject);
begin
  Application.Terminate;
end;
</code></pre>
<p><strong>Alternative solution 2</strong></p>
<p>If you want to do it without the TTrayIcon component, this article has what you need: <a href="http://delphi.about.com/od/kbwinshell/l/aa121801a.htm">System Tray Delphi Application &#8211; Quick and Easy</a></p>
]]></content:encoded>
			<wfw:commentRss>http://solutions.hans-eric.com/how-to-create-a-tray-icon-controlled-application-in-delphi/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
