<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title>Comments for Mining Delphi's demo programs</title>
<link rel="alternate" type="text/plain" href="http://dn.codegear.com/article/27984" title="Mining Delphi's demo programs" />
<link rel="self" type="application/atom+xml" href="http://dn.codegear.com/article/27984/feed" title="Comments for Mining Delphi's demo programs" />
<id>http://dn.codegear.com/article/27984</id>
<updated>2008-11-21T14:59:19-08:00</updated>
<entry>
<title>Mining Delphi's demo programs</title>
<author>
<name>Stefan Heicking</name>
<uri>http://threads.codegear.com/threads/threads.exe/userall?commentid=30903</uri>
</author>
<id>http://threads.codegear.com/threads/threads.exe/view?commentid=30903</id>
<updated>2001-12-18T23:51:39-08:00</updated>
<published>2001-12-18T23:51:39-08:00</published>
<summary>Mining Delphi's demo programs</summary>
<content>Thank you for digging out some diamonds! Now I'm encouraged to look for more gems for myself!</content>
</entry>
<entry>
<title>re: and I may be wrong but I don't like the look of this either</title>
<author>
<name>Danny Thorpe</name>
<uri>http://threads.codegear.com/threads/threads.exe/userall?commentid=30823</uri>
</author>
<id>http://threads.codegear.com/threads/threads.exe/view?commentid=30823</id>
<updated>2001-12-07T17:40:34-08:00</updated>
<published>2001-12-07T17:40:34-08:00</published>
<summary>re: and I may be wrong but I don't like the look of this either</summary>
<content>The statement Listbox1.Items := Screen.Fontsis completely safe.  Look at the implementation of TListbox.SetItems.  It calls Assign to transfer the contents of the string list into the internal stringlist.  It does not acquire a reference to the Screen.Fonts object.  This is one of many design patterns in VCL.-Danny</content>
</entry>
<entry>
<title>re: and I may be wrong but I don't like the look of this either</title>
<author>
<name>Steve Rash</name>
<uri>http://threads.codegear.com/threads/threads.exe/userall?commentid=30793</uri>
</author>
<id>http://threads.codegear.com/threads/threads.exe/view?commentid=30793</id>
<updated>2001-12-05T02:54:47-08:00</updated>
<published>2001-12-05T02:54:47-08:00</published>
<summary>re: and I may be wrong but I don't like the look of this either</summary>
<content>sorry did'nt put a suggestion for improvement..procedure TForm1.FormCreate(Sender: TObject);begin  Listbox1.Items.AddStrings(Screen.Fonts);end;or maybe procedure TForm1.FormCreate(Sender: TObject);begin  Listbox1.Items.Assign(Screen.Fonts);end;</content>
</entry>
<entry>
<title>and I may be wrong but I don't like the look of this either</title>
<author>
<name>Steve Rash</name>
<uri>http://threads.codegear.com/threads/threads.exe/userall?commentid=30792</uri>
</author>
<id>http://threads.codegear.com/threads/threads.exe/view?commentid=30792</id>
<updated>2001-12-05T02:50:16-08:00</updated>
<published>2001-12-05T02:50:16-08:00</published>
<summary>and I may be wrong but I don't like the look of this either</summary>
<content>{ Display the available fonts... }procedure TForm1.FormCreate(Sender: TObject);begin  Listbox1.Items := Screen.Fonts;end;Now surely Listbox1.Items points to a TStrings object, that Listbox1 created, and Listbox1 will destroy Items when it is destroyed.  This code moves this pointer to another TStrings object.  This will result in a memory leak.  Plus when Listbox1 is destroyed the memory Screen.Fonts refers to will be freed, resulting in possible AV's.</content>
</entry>
<entry>
<title>Well the first example is dodgy for a start...</title>
<author>
<name>Steve Rash</name>
<uri>http://threads.codegear.com/threads/threads.exe/userall?commentid=30791</uri>
</author>
<id>http://threads.codegear.com/threads/threads.exe/view?commentid=30791</id>
<updated>2001-12-05T02:39:15-08:00</updated>
<published>2001-12-05T02:39:15-08:00</published>
<summary>Well the first example is dodgy for a start...</summary>
<content>{ List all the fields in a dataset (from DBFilter) }for I := 0 to DM1.CustomerSource.Dataset.FieldCount - 1 do  ListBox1.Items.Add(DM1.Customer.Fields[I].FieldName);Whilst DM1.CustomerSource.Dataset clearly is DM1.Customer it is not the best practice to refer to it in 2 different ways in a loop.  Should DM1.CustomerSource.Dataset be changed to point to another dataset the code would fall over.</content>
</entry>
<entry>
<title>re: Some of this stuff is CRAP.</title>
<author>
<name>Danny Thorpe</name>
<uri>http://threads.codegear.com/threads/threads.exe/userall?commentid=30756</uri>
</author>
<id>http://threads.codegear.com/threads/threads.exe/view?commentid=30756</id>
<updated>2001-11-30T13:11:14-08:00</updated>
<published>2001-11-30T13:11:14-08:00</published>
<summary>re: Some of this stuff is CRAP.</summary>
<content>That particular example is also less than ideal because the strings are not localizable.  Strings displayed to the end user should be resourced so they can be translated into the end-user's language.Demo programs almost never have that degree of completeness.  The RTL, VCL, and CLX sources are the code to study closely.  That's the code that's actually used in production.-Danny</content>
</entry>
<entry>
<title>Some of this stuff is CRAP.</title>
<author>
<name>michael johnson</name>
<uri>http://threads.codegear.com/threads/threads.exe/userall?commentid=30748</uri>
</author>
<id>http://threads.codegear.com/threads/threads.exe/view?commentid=30748</id>
<updated>2001-11-29T11:11:17-08:00</updated>
<published>2001-11-29T11:11:17-08:00</published>
<summary>Some of this stuff is CRAP.</summary>
<content>I dunno, sometimes Borland goes out of it's way to write bad Pascal.Look at this supposed Gem:const  Colors: array[0..6] of TColor = (clWhite, clBlue,      clGreen, clRed, clTeal, clPurple, clLime);  ColStr: array[0..6] of string = ('White', 'Blue',     'Green', 'Red', 'Teal', 'Purple', 'Lime');The problem here is that the relationship mapping is not explicitly maintained. That is if I change the Colors array to add clButtonFace, but don't update colStr, guess what code will fail with a range check (if that's turned on) or a GPF at run time?This code would have been better served with a sub range type such astype  ColorRange = 0..6;const  Colors: array[ColorRange] of TColor = (clWhite, clBlue,      clGreen, clRed, clTeal, clPurple, clLime);  ColStr: array[ColorRange] of string = ('White', 'Blue',     'Green', 'Red', 'Teal', 'Purple', 'Lime');Now I have explicitly linked the relationship in the number of elements between the two items. If I add elements without updating the range, the compiler will flag this with &quot;number of elements differs fro declaraion&quot; or I change the range, the compiler will tell me all the places I need to update</content>
</entry>
<entry>
<title>Mining Delphi's demo programs</title>
<author>
<name>Kyle Miller</name>
<uri>http://threads.codegear.com/threads/threads.exe/userall?commentid=30745</uri>
</author>
<id>http://threads.codegear.com/threads/threads.exe/view?commentid=30745</id>
<updated>2001-11-29T08:04:25-08:00</updated>
<published>2001-11-29T08:04:25-08:00</published>
<summary>Mining Delphi's demo programs</summary>
<content>Interesting collection of tidbits. I knew those demos were good for something. ;-)</content>
</entry>
<entry>
<title>Now that you mention it...</title>
<author>
<name>Ian Marteens</name>
<uri>http://threads.codegear.com/threads/threads.exe/userall?commentid=30741</uri>
</author>
<id>http://threads.codegear.com/threads/threads.exe/view?commentid=30741</id>
<updated>2001-11-29T02:58:05-08:00</updated>
<published>2001-11-29T02:58:05-08:00</published>
<summary>Now that you mention it...</summary>
<content>... I mean, C++ Builder demos, would you call this a good (or even, acceptable) piece of code?// The problem lies in the try/catch codevoid TMastData::UpdateParts(double PartNo, long Qty){  if ((PartNo &gt; 0) &amp;&amp; (Qty != 0))  try  {    Set&lt;TLocateOption,0,1&gt; flags;    if (!Parts-&gt;Locate(&quot;PartNo&quot;, PartNo, flags))     Abort();    Parts-&gt;Edit();    PartsOnOrder-&gt;Value = PartsOnOrder-&gt;Value + Qty;    Parts-&gt;Post();  }  catch(Exception&amp; E)  {     char msg[250];     sprintf(msg,&quot;Error updating parts table for PartNo: %d&quot;, PartNo);      ShowMessage(msg);  }}The &quot;translator&quot; for the examples had followed the &quot;C++ for applications without a message loop&quot; style for exception handling. There's not a hint about the existence of a try/__finally instruction, and code is duplicated along several try/catch code instances. Moreover, those &quot;try/catch imitating try/__finally&quot; regularly finishes the catch clause with a blatant &quot;return&quot;, instead of the more appropiated &quot;rethrow&quot;.</content>
</entry>
<entry>
<title>Mining Delphi's demo programs</title>
<author>
<name>Francis Smit</name>
<uri>http://threads.codegear.com/threads/threads.exe/userall?commentid=30735</uri>
</author>
<id>http://threads.codegear.com/threads/threads.exe/view?commentid=30735</id>
<updated>2001-11-28T16:12:57-08:00</updated>
<published>2001-11-28T16:12:57-08:00</published>
<summary>Mining Delphi's demo programs</summary>
<content>C++Builder also has loads of demo's &gt;= 117, also there is loads of source code in $(BCB)\Source, most of the property editors etc are there, in addition many 3rd party groups have example code using their stuff. Also there is loads of example  code at code central, etc and finally for those like me who are fluent in both delphi and C++, you can always translate from one to the other, or just use the fact that builder compiles Delhi units.                       Happy Code mining   PS Pity Delphi cannot use builder code as easily (but I dream of the day  it will).</content>
</entry>
</feed>
