Minggu, 26 Juli 2009
How protect Excel Sheet using Delphi?
Answer:
unit UTesteProtect;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComObj;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
ExcelApp: OleVariant;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
const
// SheetType
xlChart = -4109;
xlWorksheet = -4167;
// WBATemplate
xlWBATWorksheet = -4167;
xlWBATChart = -4109;
// Page Setup
xlPortrait = 1;
xlLandscape = 2;
xlPaperA4 = 9;
// Format Cells
xlBottom = -4107;
xlLeft = -4131;
xlRight = -4152;
xlTop = -4160;
// Text Alignment
xlHAlignCenter = -4108;
xlVAlignCenter = -4108;
// Cell Borders
xlThick = 4;
xlThin = 2;
var
ColumnRange: OleVariant;
begin
{ Start Excel }
// By using GetActiveOleObject, you use an instance o
// f Word that's already running,
// if there is one.
try
// If no instance of Word is running, try to Create a new Excel Object
ExcelApp := CreateOleObject('Excel.Application');
except
ShowMessage('Cannot start Excel/Excel not installed ?');
Exit;
end;
// Add a new Workbook, Neue Arbeitsmappe offnen
ExcelApp.Workbooks.Add(xlWBatWorkSheet);
// Open a Workbook, Arbeitsmappe offnen
ExcelApp.Workbooks.Open('c:\pasta1.xls');
// Rename the active Sheet
ExcelApp.ActiveSheet.Name := 'Pasta1';
// Rename
ExcelApp.Workbooks[1].WorkSheets[1].Name := 'Pasta1';
// Insert some Text in some Cells[Row,Col]
ExcelApp.Cells[1, 1].Value := 'Test';
ExcelApp.Cells[2, 1].Value := 'http://www.delphi3000.com';
ExcelApp.Cells[3, 1].Value := FormatDateTime('dd-mmm-yyyy', Now);
// Setting a row of data with one call
//ExcelApp.Range['A2', 'D2'].Value := VarArrayOf([1, 10, 100, 1000]);
// Setting a formula
// ExcelApp.Range['A11', 'A11'].Formula := '=Sum(A1:A10)';
// Change Cell Alignement
// ExcelApp.Cells[2, 1].HorizontalAlignment := xlright;
// Change the Column Width.
ColumnRange := ExcelApp.Workbooks[1].WorkSheets[1].Columns;
ColumnRange.Columns[1].ColumnWidth := 20;
ColumnRange.Columns[2].ColumnWidth := 40;
// Change Rowheight / Zeilenhohe andern:
ExcelApp.Rows[1].RowHeight := 15.75;
// Merge cells, Zellen verbinden:
ExcelApp.Range['B3:D3'].Mergecells := True;
// Apply borders to cells, Zellen umrahmen:
ExcelApp.Range['A14:M14'].Borders.Weight := xlThick; // Think line/ Dicke Linie
ExcelApp.Range['A14:M14'].Borders.Weight := xlThin; // Thin line Dunne Linie
// Set Bold Font in cells, Fettdruck in den Zellen
ExcelApp.Range['B16:M26'].Font.Bold := True;
// Set Font Size, Schriftgro?e setzen
ExcelApp.Range['B16:M26'].Font.Size := 12;
//right-aligned Text, rechtsbundige Textausrichtung
ExcelApp.Cells[9, 6].HorizontalAlignment := xlright;
// horizontal-aligned text, horizontale Zentrierung
ExcelApp.Range['B14:M26'].HorizontalAlignment := xlHAlignCenter;
// left-aligned Text, vertikale Zentrierung
// ExcelApp.Range['B14:M26'].VerticallyAlignment := xlVAlignCenter;
{ Page Setup }
ExcelApp.ActiveSheet.PageSetup.Orientation := xlLandscape;
// Left, Right Margin (Seitenrander)
ExcelApp.ActiveSheet.PageSetup.LeftMargin := 35;
ExcelApp.ActiveSheet.PageSetup.RightMargin := -15;
// Set Footer Margin
ExcelApp.ActiveSheet.PageSetup.FooterMargin := ExcelApp.InchesToPoints(0);
// Fit to X page(s) wide by Y tall
ExcelApp.ActiveSheet.PageSetup.FitToPagesWide := 1; // Y
ExcelApp.ActiveSheet.PageSetup.FitToPagesTall := 3; // Y
// Zoom
ExcelApp.ActiveSheet.PageSetup.Zoom := 95;
// Set Paper Size:
// ExcelApp.PageSetup.PaperSize := xlPaperA4;
// Show/Hide Gridlines:
ExcelApp.ActiveWindow.DisplayGridlines := False;
// Set Black & White
ExcelApp.ActiveSheet.PageSetup.BlackAndWhite := False;
// footers
ExcelApp.ActiveSheet.PageSetup.RightFooter := 'Right Footer / Rechte Fu?zeile';
ExcelApp.ActiveSheet.PageSetup.LeftFooter := 'Left Footer / Linke Fu?zeile';
// Show Excel Version:
ShowMessage(Format('Excel Version %s: ', [ExcelApp.Version]));
// Show Excel:
// ExcelApp.Visible := True;
// Save the Workbook
//ExcelApp.SaveAs('c:\filename.xls');
// Save the active Workbook:
// ExcelApp.ActiveSheet.Protect.Password := 'Teste';
ExcelApp.ActiveSheet.Protect(Password:='Teste', DrawingObjects:=True, Contents:=True, Scenarios:=True);//;
//Contents:=True, Scenarios:=True
ExcelApp.ActiveWorkBook.SaveAs('c:\filename.xls');
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
// Quit Excel
if not VarIsEmpty(ExcelApp) then
begin
ExcelApp.DisplayAlerts := False; // Discard unsaved files....
ExcelApp.Quit;
end;
end;
end.
How protect Excel Sheet using Delphi?
Answer:
unit UTesteProtect;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComObj;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
ExcelApp: OleVariant;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
const
// SheetType
xlChart = -4109;
xlWorksheet = -4167;
// WBATemplate
xlWBATWorksheet = -4167;
xlWBATChart = -4109;
// Page Setup
xlPortrait = 1;
xlLandscape = 2;
xlPaperA4 = 9;
// Format Cells
xlBottom = -4107;
xlLeft = -4131;
xlRight = -4152;
xlTop = -4160;
// Text Alignment
xlHAlignCenter = -4108;
xlVAlignCenter = -4108;
// Cell Borders
xlThick = 4;
xlThin = 2;
var
ColumnRange: OleVariant;
begin
{ Start Excel }
// By using GetActiveOleObject, you use an instance o
// f Word that's already running,
// if there is one.
try
// If no instance of Word is running, try to Create a new Excel Object
ExcelApp := CreateOleObject('Excel.Application');
except
ShowMessage('Cannot start Excel/Excel not installed ?');
Exit;
end;
// Add a new Workbook, Neue Arbeitsmappe offnen
ExcelApp.Workbooks.Add(xlWBatWorkSheet);
// Open a Workbook, Arbeitsmappe offnen
ExcelApp.Workbooks.Open('c:\pasta1.xls');
// Rename the active Sheet
ExcelApp.ActiveSheet.Name := 'Pasta1';
// Rename
ExcelApp.Workbooks[1].WorkSheets[1].Name := 'Pasta1';
// Insert some Text in some Cells[Row,Col]
ExcelApp.Cells[1, 1].Value := 'Test';
ExcelApp.Cells[2, 1].Value := 'http://www.delphi3000.com';
ExcelApp.Cells[3, 1].Value := FormatDateTime('dd-mmm-yyyy', Now);
// Setting a row of data with one call
//ExcelApp.Range['A2', 'D2'].Value := VarArrayOf([1, 10, 100, 1000]);
// Setting a formula
// ExcelApp.Range['A11', 'A11'].Formula := '=Sum(A1:A10)';
// Change Cell Alignement
// ExcelApp.Cells[2, 1].HorizontalAlignment := xlright;
// Change the Column Width.
ColumnRange := ExcelApp.Workbooks[1].WorkSheets[1].Columns;
ColumnRange.Columns[1].ColumnWidth := 20;
ColumnRange.Columns[2].ColumnWidth := 40;
// Change Rowheight / Zeilenhohe andern:
ExcelApp.Rows[1].RowHeight := 15.75;
// Merge cells, Zellen verbinden:
ExcelApp.Range['B3:D3'].Mergecells := True;
// Apply borders to cells, Zellen umrahmen:
ExcelApp.Range['A14:M14'].Borders.Weight := xlThick; // Think line/ Dicke Linie
ExcelApp.Range['A14:M14'].Borders.Weight := xlThin; // Thin line Dunne Linie
// Set Bold Font in cells, Fettdruck in den Zellen
ExcelApp.Range['B16:M26'].Font.Bold := True;
// Set Font Size, Schriftgro?e setzen
ExcelApp.Range['B16:M26'].Font.Size := 12;
//right-aligned Text, rechtsbundige Textausrichtung
ExcelApp.Cells[9, 6].HorizontalAlignment := xlright;
// horizontal-aligned text, horizontale Zentrierung
ExcelApp.Range['B14:M26'].HorizontalAlignment := xlHAlignCenter;
// left-aligned Text, vertikale Zentrierung
// ExcelApp.Range['B14:M26'].VerticallyAlignment := xlVAlignCenter;
{ Page Setup }
ExcelApp.ActiveSheet.PageSetup.Orientation := xlLandscape;
// Left, Right Margin (Seitenrander)
ExcelApp.ActiveSheet.PageSetup.LeftMargin := 35;
ExcelApp.ActiveSheet.PageSetup.RightMargin := -15;
// Set Footer Margin
ExcelApp.ActiveSheet.PageSetup.FooterMargin := ExcelApp.InchesToPoints(0);
// Fit to X page(s) wide by Y tall
ExcelApp.ActiveSheet.PageSetup.FitToPagesWide := 1; // Y
ExcelApp.ActiveSheet.PageSetup.FitToPagesTall := 3; // Y
// Zoom
ExcelApp.ActiveSheet.PageSetup.Zoom := 95;
// Set Paper Size:
// ExcelApp.PageSetup.PaperSize := xlPaperA4;
// Show/Hide Gridlines:
ExcelApp.ActiveWindow.DisplayGridlines := False;
// Set Black & White
ExcelApp.ActiveSheet.PageSetup.BlackAndWhite := False;
// footers
ExcelApp.ActiveSheet.PageSetup.RightFooter := 'Right Footer / Rechte Fu?zeile';
ExcelApp.ActiveSheet.PageSetup.LeftFooter := 'Left Footer / Linke Fu?zeile';
// Show Excel Version:
ShowMessage(Format('Excel Version %s: ', [ExcelApp.Version]));
// Show Excel:
// ExcelApp.Visible := True;
// Save the Workbook
//ExcelApp.SaveAs('c:\filename.xls');
// Save the active Workbook:
// ExcelApp.ActiveSheet.Protect.Password := 'Teste';
ExcelApp.ActiveSheet.Protect(Password:='Teste', DrawingObjects:=True, Contents:=True, Scenarios:=True);//;
//Contents:=True, Scenarios:=True
ExcelApp.ActiveWorkBook.SaveAs('c:\filename.xls');
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
// Quit Excel
if not VarIsEmpty(ExcelApp) then
begin
ExcelApp.DisplayAlerts := False; // Discard unsaved files....
ExcelApp.Quit;
end;
end;
end.
How protect Excel Sheet using Delphi?
Answer:
unit UTesteProtect;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComObj;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
ExcelApp: OleVariant;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
const
// SheetType
xlChart = -4109;
xlWorksheet = -4167;
// WBATemplate
xlWBATWorksheet = -4167;
xlWBATChart = -4109;
// Page Setup
xlPortrait = 1;
xlLandscape = 2;
xlPaperA4 = 9;
// Format Cells
xlBottom = -4107;
xlLeft = -4131;
xlRight = -4152;
xlTop = -4160;
// Text Alignment
xlHAlignCenter = -4108;
xlVAlignCenter = -4108;
// Cell Borders
xlThick = 4;
xlThin = 2;
var
ColumnRange: OleVariant;
begin
{ Start Excel }
// By using GetActiveOleObject, you use an instance o
// f Word that's already running,
// if there is one.
try
// If no instance of Word is running, try to Create a new Excel Object
ExcelApp := CreateOleObject('Excel.Application');
except
ShowMessage('Cannot start Excel/Excel not installed ?');
Exit;
end;
// Add a new Workbook, Neue Arbeitsmappe offnen
ExcelApp.Workbooks.Add(xlWBatWorkSheet);
// Open a Workbook, Arbeitsmappe offnen
ExcelApp.Workbooks.Open('c:\pasta1.xls');
// Rename the active Sheet
ExcelApp.ActiveSheet.Name := 'Pasta1';
// Rename
ExcelApp.Workbooks[1].WorkSheets[1].Name := 'Pasta1';
// Insert some Text in some Cells[Row,Col]
ExcelApp.Cells[1, 1].Value := 'Test';
ExcelApp.Cells[2, 1].Value := 'http://www.delphi3000.com';
ExcelApp.Cells[3, 1].Value := FormatDateTime('dd-mmm-yyyy', Now);
// Setting a row of data with one call
//ExcelApp.Range['A2', 'D2'].Value := VarArrayOf([1, 10, 100, 1000]);
// Setting a formula
// ExcelApp.Range['A11', 'A11'].Formula := '=Sum(A1:A10)';
// Change Cell Alignement
// ExcelApp.Cells[2, 1].HorizontalAlignment := xlright;
// Change the Column Width.
ColumnRange := ExcelApp.Workbooks[1].WorkSheets[1].Columns;
ColumnRange.Columns[1].ColumnWidth := 20;
ColumnRange.Columns[2].ColumnWidth := 40;
// Change Rowheight / Zeilenhohe andern:
ExcelApp.Rows[1].RowHeight := 15.75;
// Merge cells, Zellen verbinden:
ExcelApp.Range['B3:D3'].Mergecells := True;
// Apply borders to cells, Zellen umrahmen:
ExcelApp.Range['A14:M14'].Borders.Weight := xlThick; // Think line/ Dicke Linie
ExcelApp.Range['A14:M14'].Borders.Weight := xlThin; // Thin line Dunne Linie
// Set Bold Font in cells, Fettdruck in den Zellen
ExcelApp.Range['B16:M26'].Font.Bold := True;
// Set Font Size, Schriftgro?e setzen
ExcelApp.Range['B16:M26'].Font.Size := 12;
//right-aligned Text, rechtsbundige Textausrichtung
ExcelApp.Cells[9, 6].HorizontalAlignment := xlright;
// horizontal-aligned text, horizontale Zentrierung
ExcelApp.Range['B14:M26'].HorizontalAlignment := xlHAlignCenter;
// left-aligned Text, vertikale Zentrierung
// ExcelApp.Range['B14:M26'].VerticallyAlignment := xlVAlignCenter;
{ Page Setup }
ExcelApp.ActiveSheet.PageSetup.Orientation := xlLandscape;
// Left, Right Margin (Seitenrander)
ExcelApp.ActiveSheet.PageSetup.LeftMargin := 35;
ExcelApp.ActiveSheet.PageSetup.RightMargin := -15;
// Set Footer Margin
ExcelApp.ActiveSheet.PageSetup.FooterMargin := ExcelApp.InchesToPoints(0);
// Fit to X page(s) wide by Y tall
ExcelApp.ActiveSheet.PageSetup.FitToPagesWide := 1; // Y
ExcelApp.ActiveSheet.PageSetup.FitToPagesTall := 3; // Y
// Zoom
ExcelApp.ActiveSheet.PageSetup.Zoom := 95;
// Set Paper Size:
// ExcelApp.PageSetup.PaperSize := xlPaperA4;
// Show/Hide Gridlines:
ExcelApp.ActiveWindow.DisplayGridlines := False;
// Set Black & White
ExcelApp.ActiveSheet.PageSetup.BlackAndWhite := False;
// footers
ExcelApp.ActiveSheet.PageSetup.RightFooter := 'Right Footer / Rechte Fu?zeile';
ExcelApp.ActiveSheet.PageSetup.LeftFooter := 'Left Footer / Linke Fu?zeile';
// Show Excel Version:
ShowMessage(Format('Excel Version %s: ', [ExcelApp.Version]));
// Show Excel:
// ExcelApp.Visible := True;
// Save the Workbook
//ExcelApp.SaveAs('c:\filename.xls');
// Save the active Workbook:
// ExcelApp.ActiveSheet.Protect.Password := 'Teste';
ExcelApp.ActiveSheet.Protect(Password:='Teste', DrawingObjects:=True, Contents:=True, Scenarios:=True);//;
//Contents:=True, Scenarios:=True
ExcelApp.ActiveWorkBook.SaveAs('c:\filename.xls');
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
// Quit Excel
if not VarIsEmpty(ExcelApp) then
begin
ExcelApp.DisplayAlerts := False; // Discard unsaved files....
ExcelApp.Quit;
end;
end;
end.
Jumat, 24 Juli 2009
BORLAND DELPHI 7 TUTORIAL - FOR WINDOWS - TUTORIAL GUIDE HELP FREE
This tutorial in pdf format so you can save it to your computer or print.
Here you leave the free download of the tutorial
Nota: The tutorial you are about to download is compressed format . rar, if you do not have a decompressor rar files you can download free 7-zip and to display the Foxit PDF Reader.
CONTENTS BORLAND DELPHI 7 TUTORIAL - FOR WINDOWS
Component Writer’s Guide
Borland Delphi 7 for Windows
Chapter 1
Overview of component creation 1-1
Class library
Components and classes
Creating components
Modifying existing controls
Creating windowed controls
Creating graphic controls
Subclassing Windows controls
Creating nonvisual components
What goes into a component?
Removing dependencies
Setting properties, methods, and events
Properties
Methods
Events
Encapsulating graphics
Registering components
Creating a new component
Creating a component with the
Component wizard
Creating a component manually
Creating a unit file
Deriving the component
Registering the component
Creating a bitmap for a component
Installing a component on the Component palette
Making source files available
Testing uninstalled components
Testing installed components
Delphi 7 Tutorial
Good tutorials pdf
Software user guide
Manuals free
Help me programming
Bible Borland
Table of Contents
Chapter 2
Object-oriented programming for component writers
Defining new classes
Deriving new classes
To change class defaults to avoid repetition
To add new capabilities to a class
Declaring a new component class
Ancestors, descendants, and class hierarchies
Controlling access
Hiding implementation details
Defining the component writer’s interface
Defining the runtime interface
Defining the design-time interface
Dispatching methods
Static methods
An example of static methods
Virtual methods
Overriding methods
Dynamic methods
Abstract class members
Classes and pointers
Chapter 3
Creating properties
Why create properties?
Types of properties
Publishing inherited properties
Defining properties
Property declarations
Internal data storage
Direct access
Access methods
The read method
The write method
Default property values
Specifying no default value
Creating array properties
Creating properties for subcomponents
Creating properties for interfaces
Storing and loading properties
Using the store-and-load mechanism
Specifying default values
Determining what to store
Initializing after loading
Storing and loading unpublished properties
Creating methods to store and load property values
Overriding the DefineProperties method
Chapter 4
Creating events
What are events?
Events are method pointers
Events are properties
Event types are method-pointer types
Event-handler types are procedures
Event handlers are optional
Implementing the standard events
Identifying standard events
Standard events for all controls
Standard events for standard controls
Making events visible
Changing the standard event handling
Defining your own events
Triggering the event
Two kinds of events
Defining the handler type
Simple notifications
Event-specific handlers
Returning information from the handler
Declaring the event
Event names start with “On”
Calling the event
Chapter 5
Creating methods
Avoiding dependencies
Naming methods
Protecting methods
Methods that should be public
Methods that should be protected
Abstract methods
Making methods virtual
Declaring methods
Chapter 6
Using graphics in components
Overview of graphics
Using the canvas
Working with pictures
Using a picture, graphic, or canvas
Loading and storing graphics
Handling palettes
Specifying a palette for a control
Off-screen bitmaps
Creating and managing off-screen bitmaps
Copying bitmapped images
Responding to changes
Chapter 7
Handling messages and system notifications
Understanding the message-handling system
What’s in a Windows message?
Dispatching messages
Tracing the flow of messages
Changing message handling
Overriding the handler method
Using message parameters
Trapping messages
Creating new message handlers
Defining your own messages
Declaring a message identifier
Declaring a message-record type
Declaring a new message-handling method
Sending messages
Broadcasting a message to all controls in a form
Calling a control’s message handler directly
Sending a message using the Windows message queue
Sending a message that does not execute immediately
Responding to system notifications using CLX
Responding to signals
Assigning custom signal handlers
Responding to system events
Commonly used events
Overriding the EventFilter method
Generating Qt events
Chapter 8
Making components available at design time
Registering components
Declaring the Register procedure
Writing the Register procedure
Specifying the components
Specifying the palette page
Using the RegisterComponents function
Providing Help for your component
Creating the Help file
Creating the entries
Making component Help context-sensitive
Adding component Help files
Adding property editors
Deriving a property-editor class
Editing the property as text
Displaying the property value
Setting the property value
Editing the property as a whole
Specifying editor attributes
Registering the property editor
Property categories
Registering one property at a time
Registering multiple properties at once
Specifying property categories
Using the IsPropertyInCategory function
Adding component editors
Adding items to the context menu
Specifying menu items
Implementing commands
Changing the double-click behavior
Adding clipboard formats
Registering the component editor
Compiling components into packages
Chapter 9
Modifying an existing component
Creating and registering the component
Modifying the component class
Overriding the constructor
Specifying the new default property value
Chapter 10
Creating a graphic control
Creating and registering the component
Publishing inherited properties
Adding graphic capabilities
Determining what to draw
Declaring the property type
Declaring the property
Writing the implementation method
Overriding the constructor and destructor
Changing default property values
Publishing the pen and brush
Declaring the class fields
Declaring the access properties
Initializing owned classes
Setting owned classes’ properties
Drawing the component image
Refining the shape drawing
Chapter 11
Customizing a grid
Creating and registering the component
Publishing inherited properties
Changing initial values
Resizing the cells
Filling in the cells
Tracking the date
Storing the internal date
Accessing the day, month, and year
Generating the day numbers
Selecting the current day
Navigating months and years
Navigating days
Moving the selection
Providing an OnChange event
Excluding blank cells
Chapter 12
Making a control data aware
Creating a data browsing control
Creating and registering the component
Making the control read-only
Adding the ReadOnly property
Allowing needed updates
Adding the data link
Declaring the class field
Declaring the access properties
An example of declaring access properties
Initializing the data link
Responding to data changes
Creating a data editing control
Changing the default value of FReadOnly
Handling mouse-down and key-down messages
Responding to mouse-down messages
Responding to key-down messages
Updating the field data link class
Modifying the Change method
Updating the dataset
Chapter 13
Making a dialog box a component
Defining the component interface
Creating and registering the component
Creating the component interface
Including the form unit
Adding interface properties
Adding the Execute method
Testing the component
Chapter 14
Extending the IDE
Overview of the Tools API
Writing a wizard class
Implementing the wizard interfaces
Installing the wizard package
Obtaining Tools API services
Using native IDE objects
Using the INTAServices interface
Adding an image to the image list
Adding an action to the action list
Deleting toolbar buttons
Debugging a wizard
Interface version numbers
Working with files and editors
Using module interfaces
Using editor interfaces
Creating forms and projects
Creating modules
Notifying a wizard of IDE events
Index
Tables
Component creation starting points
Levels of visibility within an object
How properties appear in the Object Inspector
Canvas capability summary
Image-copying methods
TWidgetControl protected methods for responding to system notifications
TWidgetControl protected methods for responding to events from controls
Predefined property-editor types
Methods for reading and writing property values
Property-editor attribute flags
Property categories
The four kinds of wizards
Tools API service interfaces
Notifier interfaces
Figures
Visual Component Library class hierarchy
Component wizard
Signal routing
System event routing
Rabu, 22 Juli 2009
Using Delphi's Excel components
The new Delphi 5 components make starting Excel very simple. Drop an ExcelApplication component on your form. If the AutoConnect property is true, Excel will start automatically when your program starts; if it's false, just call
ExcelApplication1.Connect;
when you want to start Excel. To use a running instance of Excel, if there is one, set the ConnectKind property of TExcelApplication to ckRunningOrNew, or to ckRunningInstance if you don't want to start a new instance if Excel isn't running.
Once Excel has started, you can connect other components, such as TExcelWorkbook, using their ConnectTo methods:
ExcelWorkbook1.ConnectTo(ExcelApplication1.ActiveWorkbook);Note that a workbook or worksheet must be open before you can connect to it! See How to open a workbook or How to create a workbook for code to do this.
ExcelWorksheet1.ConnectTo(ExcelApplication1.ActiveSheet as _Worksheet);
ExcelWorksheet2.ConnectTo(ExcelApplication1.Worksheets.Item['Sheet2'] as _Worksheet);
I advise you not to try to start Excel using any component except the application component, however. At least on some setups, calling the Connect method (NB not the ConnectTo method!) of a Workbook or Worksheet component will cause an exception.
Minggu, 15 Februari 2009
AnyDAC. Very High Performance using the Array DML
AnyDAC encapsulates all database server specific implementation of the Array DML commands and lets you use identical code for all server types. Obviously, the resulting performance will differ based on the server implementation; especially Oracle, MS SQL Server and IBM DB2 have very powerful support of the Array DML and the resulting performance increase is just amazing.
Please use the sample code to get a feeling for the potential performance increase within your application and network.
Introduction
This tutorial has three main sections:
- How to prepare your test environment.
- The main elements of the Array DML commands.
- The typical results of the Array DML test run.
Prepare your Test Environment
The following example works with the AnyDAC sample database environment. For further details about the installation of this database look into AnyDAC Demo Databases.
You find the demo projects in your sample directory:
- This tutorial code -
\Samples\Comp Layer\TADQuery\ExecSQL\AD03-ArrayDML or directly from article - A basic example code -
\Samples\Comp Layer\TADQuery\ExecSQL\Batch.
How does the Array DML command work?
Imagine a "use case" where you have to INSERT, UPDATE, DELETE or run any other parametrized command N times, typically one command per single record. This means, that each set of input parameters requests to execute a SQL command and is transferred separately between the client and the server. This leads to a heavy load on the network, client and server.
Array DML allows you to transport not only one, but N-sets of data within one transfer. Have a look at the following example:
ADQuery1.SQL.Text:= 'insert into ADQA_Batch_test (tint, tstring) values(:f1, :f2)';
You can speed up your code dramatically by using Array DML commands. Such commands transfer not only one, but N sets of parameters.
ADQuery1.Params.ArraySize := 100;
...
for i := 0 to ADQuery1.Params.ArraySize do begin
ADQuery1.Params[0].AsIntegers[i] := i;
ADQuery1.Params[1].AsStrings[i] := 'Test' + IntToStr(i);
end;
ADQuery1.Execute(ADQuery1.Params.ArraySize);
This means the Params property of the query is no more a one- but a two-dimensional array, that allows you to store N sets of parameter values before sending them to the server.
Usage Hints:
- Can be used for any SQL command that uses parameters (INSERT, UPDATE, DELETE ...).
- The error handling is supported on record level and described in a separate article.
- AnyDAC unifies the Array DML for different server types (no need for you do dig into the API).
Typical Results of the Array DML Test Run
The attached test code allows you to experiment within your specific environment.

Results of the test example can differ a lot depending on host and network performance. A typical picture of a local Oracle on a rather old laptop will still show > 100'000 records per second as you can see in this screen shot:

A larger Array DML ArraySize results in a higher performance (in our case up to a factor of 2000). We expect that the performance boost in your own environment will surprise you as well.

Written by Dmitry Arefiev
Performance Hints: Array DML command performance is influenced by:
- The fact that they are a lot faster on slow networks as these commands create less TCP/IP packages.
- They reduce the CPU load on the client side, as most of the time the server has to work on the array command.
- The theoretical speed of > 100'000 rec/sec is not often reached as the server normally has to evaluate triggers and indexes.
- For real large batch inserts (e.g. > 1'000'000 records), you should consider to drop and recreate non primary key indexes to reach a maximum performance.
Rabu, 11 Februari 2009
Fast Report. Grouping
In continuation of the topic on practical use of Fast Report components in complex programmes for billing, I will show you several practical examples of using grouping. For these examples I will use the payroll described in the first article 'First step in inheritance'. Reminding that a simplified form of the table has this appearance:
- Synthetic key (PK)
- Pay period
- Payer’s code
- Payer’s name
- Kind of payment (FK)
- Payment’s documents (FK)
- Date of payments
- Total payment
- Type of service (FK)
Among other things, report clients want to have a list of payments for a period, for which, the user can have the possibility to order grouping in form of payment, in form of payer’s document, in form of payments and documents, and finally, totally without grouping (in actual fact, a lot of parameters are needed for ordering, but describing the technical work of other parameters is not important). Titles and columns for all the four reports are the same, therefore, we will need one report template with two groups. Together with these groups we will be determining the table’s features.
For creating the report 'Payers list' click menu File+New…, we move to the tab 'Template' and choose basic report BaseReport (its creation has been described in the first article) and we click the flag 'Inherit the report'. In the received report, there is already one inherited group — it will be grouped in form of payments. We again add one more group of payer’s documents. The second group will be immediately by default put inside the first. When needed, the groups can change places; drag the second group with a mouse above the first, but for our report there is no need to do this.
Further, according to documentation (UserManual-ru, chap 3.1) compulsory requirement for a report with grouping is SQL inquiry with sorting of grouped fields.
A ready report has the following appearance:

On the order form report there are two flags 'Grouping in form of payments', 'Grouping in form of payer’s document' which work independent of each other.

Activation/deactivation of visibility of the group header and group footer is done with the help of the property Visible. With the method FMainReport.FindObject we will find a pointer to the title of the group and set its property Visible in accordance with the flags on the order form .We do the same as well with group basement. Then we change the line ORDER BY in SQL text. If the user had set the flag 'Kind of payment' only, then sorting must start with the field 'Form of payment' , If set only 'Payer’s document', then with the field 'Payer’s document', but if set both flags - then sorting is needed on both fields.
When working with inserted groups, there can arise need to exclude field from the SQL query (for example, when using GROUP BY), on which one of the groupings in the report is done. For example, the client can be interested in the overall sum of every subscriber in form of payment. Then there is need to group on the dates of payment by the subscriber, so that we can get one line if the subscriber has more than one payment in a day.
In this case, to activate grouping, it’s not enough to just assign False the property Visible. If such a report is run, then we will get a mistake:

Setting the property Visible:= False does not change the execution of the expression described in the property Condition, but there is a call to a non-existent field in the SQL query. The mistake can be corrected if the property Condition is assigned the value of any constant, for example 1.
For increasing the usability of the report we use one more feature of Fast Report — Dynamic groups.
Our client has already valued the comfort ability of such an interactive report, that is, when the group opens/closes by clicking the mouse on the group title in the preview window.
The main problem when using dynamic group arises during calculation of each group’s sum. I has used several variants of calculating sum:
- The easiest variant. Nothing changes either in the header or in the footer of the dynamic group. In this case, when turning, the header and the footer will be seen. I practically don’t use this variant, because the clearness of such a report is low, in my opinion.

- The most accurate variant. Sum of a group is printed in the title of the group. In this case if no additional action is taken, and then when running the report, the sum will be equal to zero. There are two exits — create special SQL query for calculating the sum or execute the report in two passes, that is setting the property frxMainReport.ExgineOptions.DoublePass:= True. In any case, for this variant you need to change the report template. Remove group footer, that is (Visible:= False), and place sum in the group title .Am always faced with the fact that users are not always comfortable with seeing the sum in front of the group. That’s where the third variant appears.
- Not very beautiful variant, but, strangely, it’s the one used most by the end users. When close the group, you need to hide the label 'Total per group' in the footer.
This type of report will have the following appearance (when close the groups):
procedure grMainFooterOnBeforePrint(Sender: TfrxComponent);
begin
if mdMainDetail.Visible then
Memo16.Text:= 'Total '+ < class="st0">'NAME_FULL'>
else
Memo16.Text := '';
end;
In this variant the problem of sum per group arises. If the sum is considered in any ordinary way, SUM (), then, when running the value will be equal to 0. In order to calculate the sum in a closed group, we need to write the following SUM ( , mdMainDetail, 1), where 1 – considering invisible mdMainDetail. - The most difficult variant. This combination 2 and 3, that is, when opening the group the sum will be shown in footer and hidden in the header, but when closing the group, footer completely hides and sum is shown in the header. In my practical, it is always enough to use the third variant.
I think, using group is very comfortable and flexible, because the number of nested levels is not limited. This facility allows building several like reports with help of simple controlling of group using one template.
Written by Irina Tsybulnikova