marco
cantu

Mastering Delphi 6

Corrections

No book can be totally error-free and Mastering Delphi 6 makes no exception. Also the tight time for publication and the limited (even if high) page count had demanded some cuts on topics I hope to be able to cover here in the coming months, as an extra bonus. (BTW, thanks to Alvaro Antunes for pointing out most of these errors while editing the Portuguese translation.)

Notice also that if you have a free download or a trial version of Delphi you'll need to recompile all the packages of the CD, as the unit formats are not compatible between the paid and the trial/free versions.

Notice that if you have a reprint of the book (something you can figure out by looking at the initial copyright page) some of these issues might have been fixed in the printed text.

Code Examples

C:\md6code Folder: A few of the code examples (probably about 2%) depend on living in a specific directory to work properly. If you move the samples files under "C:\md6code" you'll be on the safe side. Otherwise you can indeed fix a few hard-coded filenames and database location references to make a few programs work properly. This is mentioned in the readme file (although this might be far from clear) and is not in the download material.

More specific code issues are among the fixes of the related chatpers, in the list below.

Chapter 1

Page 20/21: 7th line of page 20, the Code Insight page is actually in the Editor Properties dialog box, not the Environment Options dialog. The same error is repeated in page 21, while discussing the Ctrl+Shift+I key combination, as the Block Indent combo box is in the "General" page of the on Editor Properties dialog.

Page 42: towards the middle page, the default form format is set in the new "Designer" page of the Environment Options dialog (instead of the older Preferences page).

Page 43: 4th line, the command is in fact Project -> View Source.

Chapter 4

Page 126: at the end of the sidebar, the MiniPack example is called MimiPack

EuroConv example: Some problems have been reported because of an extra .pas file, named like the project. Let me know if you have troubles and I'll post an update.

Chapter 5

Page 158 / RunProp example: The project code is missing on the CD and was missing also in my files. This meant I failed to recompile the program on the final build (I have an automatic recompile wizard) and now I've found some pretty bad errors in the code.
The listing in the book, in fact, worked perfectly in Delphi 5, but doesn't work any more in Delphi 6. The reason is that the GetPropValue function now returns an exception in case the property doesn't exists. My updated version of the program uses the IsPublishedProp function of the TypInfo unit to obtain the same effect:

  for I := 0 to ComponentCount -1 do
  begin
    // Delphi 6 version (slightly different from Delphi 5)
    if IsPublishedProp (Components[I], Edit1.Text) then
    begin
      Value := GetPropValue (Components[I], Edit1.Text);
      ListBox1.Items.Add (Components[I].Name + '.' +
        Edit1.Text + ' = ' + string (Value))
    end
    else
      ListBox1.Items.Add ('No ' + Components[I].Name + '.' +
        Edit1.Text);

The fixed code is available in the minimal RunProp.zip file (4KB)

Page 177, the first note refers tothe unit IniFile, which is in fact IniFiles, with a final s.

Chapter 8

Actions example: the code in the book is correct but one line of the source code on the CD (and the download file on my site) was changed during some testing from the correct:

ActionCount.Enabled := Memo1.Text <> '';

to the obviously wrong:

ActionCount.Enabled := Memo1.Empty Text <> '';

The latter (which is the current code in the project you'll get) won't even compile!

Chapter 9

Figure 9.4 at page 330, is slightly different from the actual output, available here:
figure 9.4

Chapter 10

ShowApp example has no project file, create a bran new one or download showapp.zip (5 KB).

Screen example has an useless extra secondary window: remove the second CreateForm call in the project file (don't know how this got in the code, as I have an older version without it!).

Vfi and Poliform examples

are missing on the CD/download files. Here are the updates, vfi.zip (7 KB) and poliform.zip (14 KB).

Chapter 11

MdArrow component: (Page 441, at the end of the section "A Complex Graphical Component") the component part of the MdPack package but it is not installed by this package, so you might see an error when opening the related sample. To make the component available at design time you have to install the MdDesPk package. The reason is explained in the section "Registering Properties Categories"at page 449/450.

Page 462: in the first paragraph of the section "An Example of Component Messages" (towards the middle of the page) you can read: "The code of this method for the Enter key’s code and sends"the same message...". A word is missing here. Should read: "The code of this method checks for the Enter key’s code..."

Chapter 12

FirstDLL is actually working OK, but McAfee ViruScan reports that the file is infected by a 'known trojan (Backdoor - SG)'. Of course the file is OK; and McAfee has updated its signature files, but in case you see it don't worry.

CallCpp example: the project file is missing from the CD. Simply create a new project, remove the main form, add add the CallCppF.pas file to the project.

Page 490: at the beginning of the section "A Simple Delphi DLL", the sequence of commands is actually "File > New > Other" (and not "File > New" as in Delphi 5). This brings up the New Items dialog, where you can find the DLL Wizard.

DynaCall example: Again the project file is missing. A standard one will do.

FormDllP example: the project group includes some older references and the projects files do refer to an internal package of mine (CntRebuildWiz) in their list of runtime packages. A new version of the entire set of files is available in FormDllP.zip (7 KB).

UseDyna and PackInfo examples: Also the UseDyna and PackInfo examples have references to the internal rebuild wizard. To recompile, open the project options dialog, go to the packages page, move to the runtime packages list at the bottom, go to the end, and get rid of the CntRebuildWiz reference.

Chapter 13

MastDet example: the data-aware controls of this example are disconnected from the corresponding data source controls in the data module: to make the program work properly you need to connect the 9 DBEdit controls and the DBNavigator to "DataModule1.dsCust" and the DBGrid controls to "DataModule1.dsOrd".

Page 563: 2nd and 3rd lines, The "Add" command is actually "Add Fields" and the "Define" command is actually "New Field".

Chapter 16, ADO

Page 722, states that "The SQL Server OLE DB Provider supports nesting". I later found out at http://support.microsoft.com/default.aspx?scid=kb;en-us;Q177138 taht this is not true.

Page 733: middle page, disconnected recordsets require the CursorLocation property to be set to clUseClient, and not the CursorType property.

Page 732/733: In discussing how to resolve update conflicts in ADO the book fails to mention that to get access to the correct value for CurValue (which corresponds to UnderlyingValue in ADO), you need to call the Resync method on the Recordset with the AffectRecords set equal to adAffectGroup, and ResyncValues set equal to adResyncUnderlyingValues. Example:

    adoCustomers.FilterGroup := fgConflictingRecords;
    adoCustomers.Filtered := true;
    adoCustomers.Recordset.Resync(adAffectGroup, adResyncUnderlyingValues)

If you do this, you can then access the correct CurValue. Failing to do this might explain why the book said it was getting the same (incorrect) value for CurValue and OldValue. I tested this on SQL Server 2000 SP2 and MDAC 2.6, using the OLEDB Provider for SQL Server. For more info see: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ado270/htm/ mdcondetectresolveconflicts.asp. (Thanks to Andy Mackie for the pointer.)

Chapter 17

ThinPlus example: This program requires Delphi's socket server (provided in Delphi's bin folder) to run. This is apparently not clear in the text. Without this program you'll see a socket error.

Chapter 18

MdRecordView component: the listing in the book has a DefineProperties method in the class interface, that I later removed (but it was not a good idea!). The program on the CD complains for the RowHeights property when loading the form (at design time or runtime). The solution, even if not elegant, it to add the following code:

procedure TMdRecordView.DefineProperties(Filer: TFiler);
begin
  // inherited;
  // skip inherited code, persisting row and column sizes
end;

which disables the persistency for the row height (so that if you change them as design time they'll be reset as the program runs). Better than the program crashing... and not an easy issue to solve differently, as the row loading code (from the base class) needs to know the row number, which we don't know until the attached dataset has been opened.

GridDemo example, mentioned at page 789 (first line) was not on the CD or download files. Here is it in GridDemo.zip (3 KB).

Chapter 20

Office 97/2000/XP differences: I've tested the examples of this chapter only with Office 97 (never found a good reason to buy later versions, sorry MS). In same cases, as for the WordCont example, you'll have to rebuild it following the same steps I used.

WordTest example, mentioned in the chapter, was missing from the CD. Here is is, WordTest.zip (4 KB)

Page 885: The WebDemo example is erroneously indicated as WebBrows.

Page 903: One of the Com+ transaction options is not described. The extra item of the list should read as follows: "Ignores Transactions" indicates that objects do not participate in transactions, regardless of whether the client has a transaction. The difference from the setting "Does not support transactions" prevents the object from being activated if the client has a transaction.

Chapter 22

Page 970: The caption of figure 22.5 is unfinished. Should have been "... with internal hyperlinks."

Chapter 23

SaxDemo1: Running the program produces the error "file not found: ***\books.xml". In fact, the file is there but is erroneously called "sample.xml". Renaming the XML file in the folder of the example to "books.xml" should fix the problem. Alternatively, change the filename hard-coded in the program.

ConvertService SOAP example: the source code is correct, but the compiled executable file is an older version that lacks the TypesList function.

Bonus Chapters

The source code for the bonus chapter on graphics in not included in the download code or companion CD. The code is available here in graphics.zip (187 KB). Notice that it is identical to the code I included in older editions of the book, as happened with the text of the chatper.