<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title>CodeCentral Submissions for Derrick  Nel</title>
<link rel="alternate" type="text/plain" href="http://cc.embarcadero.com/" title="CodeCentral Submissions for Derrick  Nel" />
<id>http://cc.embarcadero.com/</id>
<generator url="http://atomnet.sourceforge.net/" version="0.4.3.30095">Generated by Atom.NET</generator>
<modified>2013-05-25T11:00:01-07:00</modified>
<entry>
<title>Coding Tip...</title>
<link rel="alternate" type="text/html" href="http://cc.embarcadero.com/Item/17353" title="Coding Tip..." />
<link rel="enclosure" type="application/zip" href="http://cc.embarcadero.com/Download.aspx?id=17353" title="Coding Tip..." length="6339" />
<author>
<name>Derrick  Nel</name>
</author>
<id>http://cc.embarcadero.com/Item/17353</id>
<updated>2002-01-14T05:40:33-08:00</updated>
<published>2002-01-14T05:40:33-08:00</published>
<summary>dynamic object creation technique..</summary>
<content>CODING TIP When one creates objects dynamically, as needed, your code inevitably becomes quite messy.  Checking to see if the object exists before creating it, eg.if FMyVariable = nil then  FMyVariable := TMyClass.Create;Checking to see if the object exists before destroying it, e.gif FMyVariable &lt;&gt; nil then  FreeAndNil(FMyVariable) Checking to see if the object exists before using it, e.gif FMyVariable = nil thenbegin  FMyVariable := TMyClass.Create;  FMyVariable.SomeMethod;end;OR if FMyVariable &lt;&gt; nil then  FMyVariable.SomeMethod;Inevitably your code becomes scattered with code like the fragments shown above making maintenance a real difficult task.  If you needed to change the create you would have to hunt all over looking for the &quot;if &lt;&gt; nil then create&quot; or &quot;if = nil then create&quot;,  with 4 simple methods you can neaten up your code and give maintenance programmers a break.The four simple methods are :procedure CreateObject;procedure FreeObject;function ObjectAllocated: Boolean;procedure ObjectNeeded;and this is how the code for each method looks;procedure CreateObject;begin  FObject := TObject.Create;end;procedure FreeObject;begin  if ObjectAllocated then    FreeAndNil(FObject);end;function ObjectAllocated: Boolean;begin  Result := (FObject &lt;&gt; nil);end;procedure ObjectNeeded;begin  if not ObjectAllocated then    CreateObject;end;And that&#8217;s it, so instead of using :&quot;If FObject &lt;&gt; nil then&quot; you use &quot;if ObjectAllocated then&quot;, when you need the object simply call ObjectNeeded, and to destroy the object simply call FreeObject.  All the nitty-gritty if existance checking is already taken care of.  Good luck,Derrick&#8230;.(dnel@oldmutual.com)&quot;programming in VB is like kicking a dead whale down the beach&quot;&quot;..</content>
</entry>
<entry>
<title>CUSTOM ACTIONS (&quot;pay it forward&quot;)</title>
<link rel="alternate" type="text/html" href="http://cc.embarcadero.com/Item/17204" title="CUSTOM ACTIONS (&quot;pay it forward&quot;)" />
<link rel="enclosure" type="application/zip" href="http://cc.embarcadero.com/Download.aspx?id=17204" title="CUSTOM ACTIONS (&quot;pay it forward&quot;)" length="11059" />
<author>
<name>Derrick  Nel</name>
</author>
<id>http://cc.embarcadero.com/Item/17204</id>
<updated>2001-12-20T23:47:30-08:00</updated>
<published>2001-12-20T23:47:30-08:00</published>
<summary>3 Custom Actions, which wrap the messagedlg function</summary>
<content>PAY  IT  FORWARDThe Delphi community is great! Tons of tutorials, articles, code snippets, experts and even full applications are posted onto the net by members of the Delphi community daily, and most are free.  The unselfish sharing of knowledge by community members has always fascinated me.  Color, religion, nationality, social standing and all the other trivial things that divide mankind are not important, no matter who you are, where you come from, there is a entire community willing to teach you Delphi, all you need is the desire.For the past 2 years I have been an avid student of this community and now I too wish to contribute.  It's been all one way thus far, take, take, take, and take, now its time to &quot;pay it forward&quot;.  First is my first posting of any kind and I hope someone can use this code, I do.The code.There are 2 packages, ksMsgActns50 (runtime) and ksMsgActnsDsgn50 (design time), OPEN ksMsgActns50.dpk, do a BUILD ALL, then OPEN ksMsgActnsDsgn50.dpk and INSTALL.If all goes well you will have just installed 3 custom actions, namely: &#183;TMsgDlgAction,&#183;TMsgDlgPosAction,&#183;and TConfirmationAction.They are basically actions that wrap the MessageDlg function, the first two allow you to specify the message, required mouse buttons and message dialog type (information, confirmation, warning, error and the custom type).  There is an OnClick event that is triggered when the dialog is closed and the ModalResult of the dialog is passed as the second parameter in the event handler (first being SENDER).  The MsgDlgPos action also allows you to specify the x and y co-ordinates of where the dialog should be displayed (MessageDlgPos function), the default x co-ordinate is -1, so too is the y co-ordinate, if either are still -1 when the action is invoked the dialog will be centered (MessageDlg function).There are custom action classes, so creating specific descendants is a fairly simply procedure.   The TConfirmationAction is an example of such a descendant, this action always invokes a confirmation dialog box, with a &quot;Yes&quot; and &quot;No&quot; mouse buttons, you can specify the message and pos if required.  It has 2 events of note, an OnYesClick and an OnNoClick, useful for all those pesky questions, e.g. &quot;Are you sure, you want to whatever ?&quot;.  Unfortunately the MessageDlg functions don't support a &quot;Don't ask me this question again.&quot; Checkbox with persistence, mmmmm, perhaps I'll look into that&#8230;.Some uses.The confirmation action can be used on delete buttons, confirm the users intention to delete, and write the deletion code in the OnYesClick event handler.  You could place an ActionList in a DataModule and all MessageDlg Actions in the ActionList, this would group all of them together in a central place, along with the code to execute on a yes, no, retry, ignore, whatever click.Anyway, is not much but it is a start!Constructive criticism is welcome, although not always enjoyed B-)Here is a list of more actions I have written, but was informed that they now ship with Delphi 6, if anyone wants them drop me an email&#183;TOpenDialogAction (action invokes open dialog, open picture too),&#183;TSaveDialogAction (action invokes save dialog, save picture too),&#183;TFontDialogAction (action invokes font dialog),&#183;TColorDialogAction (action invokes color dialog),&#183;TPrintDialogAction (action invokes print dialog, printer setup dialog too),&#183;TFindDialogAction (action invokes find dialog, replace dialog too).Derrick Nel (dnel@oldmutual.com)&quot;Programming in visual basic is like kicking a dead whale down a beach !!&quot;</content>
</entry>
</feed>
