Flylib.com
List of Listings
Previous page
Table of content
Chapter 2: Delphi and C++ Language Basics
Listing 2-1: Console application
Listing 2-2: Basic text output
Listing 2-3: The updated console application
Listing 2-4: Displaying several lines of text
Listing 2-5: Exception to the semicolon rule
Listing 2-6: Write and WriteLn text output
Listing 2-7: Displaying an empty line
Listing 2-8: Variable declarations
Listing 2-9: Simple assignment statements
Listing 2-10: Real and integer division
Listing 2-11: The mod operator
Listing 2-12: The unary plus operator
Listing 2-13: Arithmetic operator precedence
Listing 2-14: Reading values with ReadLn
Listing 2-15: Working with user data
Listing 2-16: A shorter version of the total cost application
Listing 2-17: Delphi console application with the C++Builder icon
Listing 2-18: The source code of a C console application
Listing 2-19: Basic text output with the printf statement
Listing 2-20: Using the getch() function to pause application execution
Listing 2-21: A simple C++ console application
Listing 2-22: Displaying several lines of text with cout
Listing 2-23: Declaring variables in C++
Listing 2-24: Declaring variables in C++, revisited
Listing 2-25: Initializing variables in C++
Listing 2-26: Using compound operators
Listing 2-27: Working with user data
Chapter 3: Conditions
Listing 3-1: A simple if-then statement
Listing 3-2: Two if-then statements
Listing 3-3: The if-then-else statement
Listing 3-4: A nested if-then statement
Listing 3-5: Multiple if-then statement
Listing 3-6: Using the Boolean not operator
Listing 3-7: Using the Boolean and operator
Listing 3-8: Using the Boolean or operator
Listing 3-9: Using the shr and shl operators
Listing 3-10: A long if-then statement
Listing 3-11: A simple case statement
Listing 3-12: Testing a range of values
Listing 3-13: Testing a list of values
Listing 3-14: The case-else statement
Listing 3-15: Nested case statements
Listing 3-16: A simple if statement
Listing 3-17: A simple if-else statement
Listing 3-18: Nested and multiple if statements in C++
Listing 3-19: The conditional operator
Listing 3-20: Fall-through
Chapter 4: Iterations
Listing 4-1: A simple for loop
Listing 4-2: Char counter
Listing 4-3: Displaying the ASCII character table
Listing 4-4: For loop with typecasting
Listing 4-5: Displaying the multiplication table
Listing 4-6: The for-downto loop
Listing 4-7: The for-in loop
Listing 4-8: A simple while loop
Listing 4-9: A simple repeat-until loop
Listing 4-10: An erroneous repeat-until loop
Listing 4-11: Breaking out of a loop
Listing 4-12: An infinite while loop
Listing 4-13: The Continue procedure
Listing 4-14: The while loop
Listing 4-15: The do-while loop
Listing 4-16: A simple for loop
Listing 4-17: Using compound operators in the for loop
Listing 4-18: A C++ for-downto loop
Listing 4-19: A weird-looking for loop
Listing 4-20: An infinite for loop
Listing 4-21: A pretty unusual for loop
Listing 4-22: Declaring a counter variable in the for loop
Chapter 5: Procedures and Functions
Listing 5-1: Inc and Dec procedures
Listing 5-2: Function calls
Listing 5-3: Our first procedure
Listing 5-4: Calling the Hello procedure
Listing 5-5: Short-circuit evaluation bug
Listing 5-6A: Public constants and variables in a unit
Listing 5-6B: Using public constants and variables
Listing 5-7: Unit initialization
Listing 5-8A: Global variables in the project file
Listing 5-8B: Global variables in a unit
Listing 5-9: Value parameter example
Listing 5-10: Variable parameter example
Listing 5-11: Default parameter example
Listing 5-12: A simple recursive procedure
Listing 5-13: A recursive function
Listing 5-14: Forward declaration
Listing 5-15: Overloaded functions
Listing 5-16: An inlined function
Listing 5-17: Using the RTLVersion constant to determine the compiler
Listing 5-18: A simple procedure
Listing 5-19: A simple function
Listing 5-20: Delphi version of the Max3 function
Listing 5-21: The C++ version of the Max3 function
Listing 5-22: Two more versions of the Max3 function using the conditional
Listing 5-23: Passing by value and by reference
Listing 5-24: Function prototypes
Listing 5-25: Using static local variables
Listing 5-26: Overloaded functions
Listing 5-27A: The my_math.cpp file
Listing 5-27B: The my_math.h file
Listing 5-27C: Including a custom header file
Listing 5-28A: An updated version of the my_math.cpp file
Listing 5-28B: Using an external variable
Chapter 6: Arrays and Strings
Listing 6-1: Array element access
Listing 6-2: Accessing array elements in a loop
Listing 6-3: Low and High functions
Listing 6-4: Using array constants
Listing 6-5: Using strings with the case statement
Listing 6-6: A simple two-dimensional array
Listing 6-7: Creating a dynamic array
Listing 6-8: Working with a dynamic multidimensional array
Listing 6-9: Open array parameters
Listing 6-10: Function with an open array parameter
Listing 6-11: ShortString facts
Listing 6-12: Searching a string with the Pos function
Listing 6-13: Manual character searching
Listing 6-14: Using the Insert procedure
Listing 6-15: Using the Delete procedure
Listing 6-16: Using the Copy function
Listing 6-17: C++ arrays
Listing 6-18: Using the sizeof operator to determine the number of elements in an array
Listing 6-19: Initializing only some of the elements in an array
Listing 6-20: Using a two-dimensional array in C++
Listing 6-21: Initializing a multidimensional array in Delphi
Listing 6-22: Initializing multidimensional arrays in C++
Listing 6-23: Using character arrays
Listing 6-24: Using common string functions
Chapter 7: User-Defined Types
Listing 7-1: Working with sets
Listing 7-2: Using records
Listing 7-3: Using typedef to create data type aliases
Listing 7-4: Using structures
Chapter 8: Basic File I/O
Listing 8-1: Writing text to a text file
Listing 8-2: Reading text from a text file
Listing 8-3: Checking I/O errors
Listing 8-4: Copying a text file
Listing 8-5: Loading a text file into a dynamic array
Listing 8-6: Working with typed files
Listing 8-7: Copying files using BlockRead and BlockWrite
Chapter 9: Pointers
Listing 9-1: Using a simple typed pointer
Listing 9-2: Using an untyped pointer
Listing 9-3: Loading a file into a dynamically allocated memory block
Listing 9-4: Accessing an array through a pointer
Listing 9-5: Accessing the string through a pointer
Listing 9-6: Dynamically creating records
Listing 9-7: Pointer basics
Listing 9-8: Void pointers
Listing 9-9: Accessing array elements through a pointer
Listing 9-10: Accessing structure fields through a pointer
Listing 9-11: Dynamic variables in C++
Chapter 10: Object-Oriented Programming
Listing 10-1: Working with records
Listing 10-2: Accessing records through pointers
Listing 10-3: Using an object
Listing 10-4: The completed class
Listing 10-5: The TAnimal class unit
Listing 10-6: Polymorphic calls
Listing 10-7: Accessing the public fields of the TAnimal class
Listing 10-8: The complete C++ TAnimal class
Listing 10-9: Inline methods
Listing 10-10A: The Animal.h file
Listing 10-10B: The Animal.cpp file
Listing 10-11: Using AnsiStrings
Listing 10-12: Using ofstream and ifstream classes to read and write text to a file
Chapter 11: Designing the User Interface
Listing 11-1: Source code of the main form
Listing 11-2: Reversing a string
Listing 11-3: Displaying parent and owner information
Listing 11-4A: The main form's .cpp file
Listing 11-4B: The main form's .h file
Listing 11-5: Accessing component properties in code
Chapter 12: Using Forms
Listing 12-1: Assigning focus to a control
Listing 12-2: An empty OnMouseDown event handler
Listing 12-3: Saving initial mouse coordinates
Listing 12-4: An empty OnMouseMove event handler
Listing 12-5: Moving the form in the OnMouseMove event
Listing 12-6: Finishing the moving process
Listing 12-7: Using the OnCreate and OnDestroy events
Listing 12-8: Dynamically creating a button
Listing 12-9: A method compatible with the OnClick event
Listing 12-10: Displaying the form
Listing 12-11A: The main project file of a Delphi VCL Forms application
Listing 12-11B: The main project file of a C++Builder VCL Forms application
Listing 12-12: Dynamically creating an empty form
Listing 12-13: Creating a form without an owner
Listing 12-14: Dynamically creating a modal form
Listing 12-15: Creating a modeless form
Listing 12-16: Releasing a modeless form from memory
Listing 12-17A: Creating the form only if it doesn't exist
Listing 12-17B: Creating the form only if it doesn't exist, C++ version
Listing 12-18A: The proper way to destroy a modeless form
Listing 12-18B: The proper way to destroy a modeless form, C++ version
Listing 12-19: Using the custom dialog box
Listing 12-20: Dynamically creating the dialog box
Listing 12-21A: Creating the splash form
Listing 12-21B: Creating the splash form, C++ version
Listing 12-22: Displaying the splash screen
Chapter 13: Delphi and C++ Exception Handling
Listing 13-1A: Catching an exception in Delphi
Listing 13-1B: Catching an exception in C++
Listing 13-2: Dividing two values
Listing 13-3A: Handling specific exceptions
Listing 13-3B: Handling specific exceptions in C++
Listing 13-4A: Reraising exceptions in Delphi
Listing 13-4B: Reraising exceptions in C++
Listing 13-5A: Raising exceptions in Delphi
Listing 13-5B: Raising exceptions in C++
Listing 13-6: Using the exception object
Listing 13-7A: Working with a custom exception
Listing 13-7B: Declaring a custom exception in C++
Listing 13-7C: Working with a custom exception in C++
Listing 13-8A: Dynamically creating a form with resource protection, Delphi version
Listing 13-8B: Dynamically creating a form with resource protection, C++ version
Listing 13-9: Dynamically creating a form with resource protection, revisited
Listing 13-10: Nested blocks
Listing 13-11: Logging unhandled exceptions
Listing 13-12: A custom OnException event handler
Listing 13-13: Assigning the event handler to the OnException event
Chapter 14: Using Components
Listing 14-1: The least sophisticated way of working with a large number of components
Listing 14-2: Searching for a specific component
Listing 14-3A: Using the FindComponent method
Listing 14-3B: Using the FindComponent method in a C++Builder VCL application
Listing 14-4A: Determining the object's class at run time
Listing 14-4B: Determining the object's class in a C++Builder VCL Forms application
Listing 14-5A: Using the is operator to find and update all buttons on a form
Listing 14-5B: Using C++ dynamic casting to find and update all buttons on a form
Listing 14-6: Changing the message box type
Listing 14-7: Using the Sender parameter to identify the component that called the event handler
Listing 14-8A: Using the Tag property to change the message box type, Delphi version
Listing 14-8B: Using the Tag property to change the message box type, C++ version
Listing 14-9: Adding a new item to the list box
Listing 14-10: Copying an entire string list
Listing 14-11: Changing the label's font
Listing 14-12: Moving multiple items from one list box to another
Listing 14-13: Using the BeginUpdate and EndUpdate methods to optimize list box operations
Listing 14-14: Adding unique items to a list box
Listing 14-15: MessageDlg related data types and constants
Listing 14-16: Adding unique items to a list box, revisited
Listing 14-17: Portions of the TStrings and TStringList class declarations
Listing 14-18: Loading the text files to TStringList objects
Listing 14-19: Releasing the string lists from memory
Listing 14-20: Locating a value using the Values property of the TStringList class
Listing 14-21: Using TRadioGroup radio buttons
Listing 14-22: Scrolling an image
Chapter 15: Standard VCL Components
Listing 15-1: Displaying hints in the OnHint event
Listing 15-2: Changing the background color of the form
Listing 15-3: Modifying the Font property of a TLabel component
Listing 15-4: Creating the code completion list
Listing 15-5: Displaying the code completion list
Listing 15-6: Code completion
Listing 15-7: Creating the code completion list, revisited
Listing 15-8: The ShowMessage button related code
Listing 15-9: Implementation of the ShowMessage user interface item
Listing 15-10: Moving the validation code to a function
Listing 15-11: The OnExecute event handler
Listing 15-12: Updating the ShowAction action
Chapter 16: Building a Text Editor
Listing 16-1: Loading a text document
Listing 16-2: Saving the document using the Save As dialog box
Listing 16-3: Creating a new document
Listing 16-4: The function that enables the user to save/discard changes
Listing 16-5: The updated New and Open actions
Listing 16-6: The OnExecute and OnUpdate event handlers of the Undo action
Listing 16-7: Cut and Copy OnExecute event handlers
Listing 16-8: The Paste action
Listing 16-9: The Delete action
Listing 16-10A: Searching for text, Delphi version
Listing 16-10B: Searching for text, C++ version
Listing 16-11: The OnReplace event handler
Chapter 17: The Multiple Document Interface
Listing 17-1: Creating a common open dialog box that allows the user to select multiple files
Listing 17-2A: Creating child instances and loading selected images, Delphi version
Listing 17-2: B Creating child instances and loading selected images, C++ version
Listing 17-3: The Window menu commands
Listing 17-4: Inverting colors
Listing 17-5: Inverting colors in C++
Chapter 18: Working with Files
Listing 18-1: Searching for files
Listing 18-2: Enumerating drives with the GetLogicalDrives function
Listing 18-3: Enumerating drives using the GetDriveType function
Listing 18-4: Using the TIniFile Class
Listing 18-5: Writing to the Registry using the TRegistryIniFile class
Listing 18-6: Using the TRegistry class
Listing 18-7: Using the TFileStream class
Listing 18-8: Saving TMemo contents to a stream
Listing 18-9: Using the CopyFrom method to copy files
Chapter 19: Desktop Database Programming
Listing 19-1: OnExecute event handlers
Listing 19-2: The application logic of the Add New Movie dialog box
Listing 19-3: Incremental filtering
Chapter 20: Advanced Development Topics
Listing 20-1: The OnDragOver event handler
Listing 20-2: Accepting items from the TypeList list box
Listing 20-3: Not the best way to instantiate controls
Listing 20-4: Using polymorphism to create controls
Listing 20-5: Registering classes
Listing 20-6: Using class references to create controls
Listing 20-7: Accepting items from the AvailableList list box
Listing 20-8: Dragging an item from one list to another
Listing 20-9: Calling the BeginDrag method
Listing 20-10: Ending drag and drop with the EndDrag method
Listing 20-11: Windows message details
Listing 20-12: Several standard Windows messages
Listing 20-13: The WM_MOVE message method
Listing 20-14: Reading coordinates from the lParam value
Listing 20-15: Using a message-related record
Listing 20-16: Automatically moving another form in the WM_MOVE message handler
Listing 20-17: Enabling the user to move the form by clicking on its client area
Listing 20-18: A custom message
Listing 20-19: Handling the custom message
Listing 20-20: Playing with messages
Listing 20-21: Registering the main form as the drop target
Listing 20-22: Determining the number of dropped files
Listing 20-23: Working with items dropped from the Windows Explorer
Chapter 21: Dynamic Link Libraries
Listing 21-1: The basic source code for a DLL
Listing 21-2: A simple DLL
Listing 21-3: The FirstLib.dll import unit
Listing 21-3: Testing the Max3 routine imported from the FirstLib.dll
Listing 21-4: A DLL routine that creates and displays an empty form
Listing 21-5: Calling a procedure from a dynamically loaded DLL
Listing 21-6: Linking the DLL with the host application
Listing 21-7: The proper way to display a VCL form that resides in the DLL
Listing 21-8: Routines that manage the memory in the DLL
Listing 21-9: Using the GetStringData and the FreeStringData routines to retrieve a localized string from the DLL
Listing 21-10: Doing things the API way
Listing 21-11: Calling the GetStringDataEx function
Listing 21-12: Basic source code of a C++Builder DLL
Listing 21-13: Two DLL functions (not counting DLLEntryPoint)
Listing 21-14A: The DLL's source file (MainDLLUnit.cpp)
Listing 21-14B: The DLL's header file (MainDLLUnit.h)
Listing 21-15: Executing code when the DLL is loaded and unloaded
Listing 21-16: DllEntryPoint in a Delphi DLL
Listing 21-17: C++ DLL with VCL forms (MyDLL.dll)
Listing 21-18: Dynamically loading a DLL in C++
Chapter 22: Graphics Programming
Listing 22-1: Using the RGB function
Listing 22-2: Drawing lines with MoveTo and LineTo
Listing 22-3: Playing with styles
Listing 22-4: Drawing lines
Listing 22-5: Working with Brush styles
Listing 22-6: Drawing text
Listing 22-7: The TextRect method
Listing 22-8: Using the DrawText function
Listing 22-9: Using the TextWidth function
Listing 22-10: Using API functions to draw on the form
Listing 22-11: Using the GetWindowDC function
Listing 22-12: Drawing a simple gradient
Listing 22-13: Handling WM_ERASEBKGND to eliminate flicker
Listing 22-14: Another way to draw gradients
Listing 22-15: Drawing gradients that support custom colors
Listing 22-16: Drawing bitmaps
Listing 22-17: Randomly drawing colored rectangles
Listing 22-18: Preparing the back buffer and randomizing the flakes
Listing 22-19: Drawing the snowflakes
Listing 22-20: Animating the snowflakes
Listing 22-21: Using the BitBlt function to draw bitmaps
Listing 22-22: Drawing snowflakes on the desktop
Chapter 23: Creating Win32 API Applications
Listing 23-1: A very simple API application
Listing 23-2: The simple API application that only displays the main window
Listing 23-3: The Menu.rc resource file
Listing 23-4: Creating the Previous and Next buttons
Listing 23-5: Displaying the open dialog box
Listing 23-6: Extracting icons
Listing 23-7: The File Ø Open command
Listing 23-8: Drawing icons and text in response to the WM_PAINT message
Listing 23-9: The Icon Viewer
Listing 23-10: A simple C++ API application
Chapter 24: Component Development Essentials
Listing 24-1: The source code of the TSimple component
Listing 24-2: Simple properties
Listing 24-3: Boolean and enumerated properties
Listing 24-4: A set property
Listing 24-5: Default property values
Listing 24-6: A simple method
Listing 24-7: Overriding virtual methods
Listing 24-8: Calling a virtual method
Listing 24-9: Properly defining default property values
Listing 24-10: The Limited property's write method
Listing 24-12: The TSimple component with the OnAccess event
Listing 24-13: The TStringsCache component
Listing 24-14: Creating a property group
Listing 24-15A: TCPPSimple component's source file
Listing 24-15B: TCPPSimple component's header file
Chapter 25: Customizing Existing Components
Listing 25-1: The AnimatedForm
Listing 25-2: The LoadLibrary method for loading rich text documents from a DLL
Listing 25-3: The ExportResource method for exporting individual resources from the DLL to the disk
Chapter 26: Advanced Component Programming
Listing 26-1: The entire character list
Listing 26-2: The updated TCharacterBox component that shares a single read method among all three custom properties
Listing 26-3: The DrawItem method of the TCharacterBox component
Listing 26-4: The SaveToFile method
Listing 26-5: The LoadFromFile method
Chapter 27: Printing, Creating PDF Documents, and Refactoring
Listing 27-1: Printing the contents of a TMemo component
Listing 27-2: The Print method of the TTextPrinter component
Listing 27-3: A simple PDF document
Listing 27-4: TPDFExport component, the beginning
Listing 27-5: StartObject and EndObject methods
Listing 27-6: Generating the document information dictionary
Listing 27-7: Generating the font object
Listing 27-8: Reformatting the strings in the component's Strings property
Listing 27-9: Generating page contents objects
Listing 27-10: Generating the page tree and the page objects
Listing 27-11: Generating the cross-reference table and the file trailer
Listing 27-12: Using the TPDFExport component to save TMemo text to PDF
Chapter 28: Image Processing
Listing 28-1: The utility code
Listing 28-2: Inverting colors using the Pixels property
Listing 28-3: The Solarize effect
Listing 28-4: Disabling an image
Listing 28-5: The AcquireDisabled procedure
Chapter 29: .NET Framework Programming
Listing 29-1: Using both the Delphi RTL and the FCL in a Delphi for .NET console application
Listing 29-2: The source code of a C# console application
Listing 29-3: if and switch statements
Listing 29-4: Arrays in C#
Listing 29-5: Instantiating and using the System.Array class
Listing 29-6: Using the ArrayList class
Listing 29-7: A very simple C# class library
Listing 29-8: Using HelloClass from the C# TestLib class library
Listing 29-9A: Using a Delphi for .NET package in a C# application
Listing 29-9B: Using a Delphi for .NET package in a VB.NET application
Listing 29-10: A method without parameters
Listing 29-11: Method that accepts a single parameter by value
Listing 29-12: Accepting a larger number of parameters
Listing 29-13: Passing parameters by reference
Listing 29-14: Calling a method that accepts parameters by reference
Listing 29-15: C# out parameters
Listing 29-16: Passing objects to methods
Listing 29-16: Overloaded methods
Listing 29-17: Passing a variable number of parameters to a method
Listing 29-18: C# enumerations
Listing 29-19: Catching several exceptions
Listing 29-20: Using exception objects, throwing and rethrowing exceptions
Listing 29-21: Reading text files with the StreamReader class
Listing 29-22: Using the Wordware.IOLibrary.TextFileReader class to view text files
Listing 29-23: The source code of a basic Windows.Forms form with a single Label component
Listing 29-24A: The entry point of a Delphi for .NET Windows.Forms application
Listing 29-24B: The entry point of a C# Windows.Forms application
Listing 29-25: Assigning multiple event handlers to an event in a Delphi for .NET Windows.Forms application
Listing 29-26: Assigning multiple event handlers to an event in a C# Windows.Forms application
Listing 29-27: Dynamically creating a Windows.Forms.Button control
Listing 29-28: Loading an entire text file into a Windows.Forms.TextBox control
Listing 29-29: Creating child forms
Chapter 30: Advanced Win32 and .NET Programming
Listing 30-1: Forward class declaration
Listing 30-2: Instantiating the enumerator class in the GetEnumerator method
Listing 30-3: The TImageCacheEnumerator class
Listing 30-4: Exporting images
Listing 30-5: The Library class
Listing 30-6: The LibraryEnumerator class
Listing 30-7: Records in Delphi for Win32 and Delphi for .NET
Listing 30-8: Structures in C#
Listing 30-9: Overloading operators in Delphi
Listing 30-10: Overloading operators in C#
Listing 30-11: C# indexers
Listing 30-12: Using a custom delegate in Delphi for Win32
Listing 30-13: A TButton descendant with a multicast OnClick event
Listing 30-14: Using delegates
Listing 30-15: Delegates and events in C#
Listing 30-16: GDI+ essentials
Listing 30-17: Working with images, text, texture, and gradient brushes
Previous page
Table of content
Inside Delphi 2006 (Wordware Delphi Developers Library)
ISBN: 1598220039
EAN: 2147483647
Year: 2004
Pages: 212
Authors:
Ivan Hladni
BUY ON AMAZON
Inside Network Security Assessment: Guarding Your IT Infrastructure
Introduction to Assessing Network Vulnerabilities
Laws, Mandates, and Regulations
Risk Assessment Best Practices
IT Security Architecture and Framework
Analysis
Introducing Microsoft ASP.NET AJAX (Pro - Developer)
The AJAX Revolution
The Pulsing Heart of ASP.NET AJAX
Partial Page Rendering
The AJAX Control Toolkit
Building AJAX Applications with ASP.NET
Mastering Delphi 7
The Architecture of Delphi Applications
Client/Server with dbExpress
Internet Programming: Sockets and Indy
The Microsoft .NET Architecture from the Delphi Perspective
Appendix B Extra Delphi Tools from Other Sources
The Lean Six Sigma Pocket Toolbook. A Quick Reference Guide to Nearly 100 Tools for Improving Process Quality, Speed, and Complexity
Using DMAIC to Improve Speed, Quality, and Cost
Voice of the Customer (VOC)
Descriptive Statistics and Data Displays
Complexity Value Stream Mapping and Complexity Analysis
Selecting and Testing Solutions
Visual Studio Tools for Office(c) Using C# with Excel, Word, Outlook, and InfoPath
Working with the Range Object
Working with the Explorers and Inspectors Collections
Deployment
Part Four. Advanced Office Programming
VSTO Support for the WordML File Format
User Interfaces in C#: Windows Forms and Custom Controls
Designing with Classes and Tiers
Custom Controls
Design-Time Support for Custom Controls
Dynamic User Interface
Help and Application-Embedded Support
flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net
Privacy policy
This website uses cookies. Click
here
to find out more.
Accept cookies