Pascal Newsletter #18 - 05-MAR-2001
INDEX
1. A FEW WORDS FROM THE EDITOR
2. ANGLED TEXT
3. BORDERWIDTH - ERROR IN COMPONENTS PROPERTY
4. WORKSHOP
________________________________________________________________________
1. A FEW WORDS FROM THE EDITOR
If you haven't seen the demo yet, you won't understand what you are
missing... With the JfControls Library you can easily give your
applications a visual quality that will make them stand out from the
rest and will impress your potential clients. The professional look your
applications can attain with these controls can help you sell, but it's
not all about a matter of appearances: the Library solves many common
programming problems and simplifies many programming tasks, so that you
can spend your time focused on what you have to do, not wasting it on
trivial stuff, this way shortening the application development cycle and
helping you produce better-quality applications.
Donwload JfSetup and the Demo, and install them to get the Key Number (a
unique number that identifies each installation of the library) that you
need in order to be able to fill in the registration form of the
JfControls Library Drawing (or "raffle" if you like it). It's free, and
remember that the deadline to register is Thursday, March 15 at 20:00
GMT. The winner of the license will be determined by the last three
digits of the March-17 draw of the National Lottery of Spain, and we'll
publish the winner number in the next issue of this newsletter. For more
information about the drawing:
http://www.latiumsoftware.com/jfcontrols/index.php?lang=en
Best regards,
Ernesto De Spirito
eds2008 @ latiumsoftware.com
________________________________________________________________________
JfControls Library. Multi-language. Multi-appearance. Skins. Privileges.
More than 40 integrated and customizable components. Impressive GUI.
Centralized resources administration. Multiple programming problems
solved. For Delphi 3-2006 & C++ Builder 3-6. http://www.jfactivesoft.com
________________________________________________________________________
2. ANGLED TEXT
You surely have seen some labels and other components allow you to
rotate the text. For example with the JfControls Library you can rotate
the captions of labels, buttons, checkboxes, radiobuttons, list items,
menu items, etc. You can achieve the same effect using the lfEscapement
and lfOrientation fields of the font object structure, that store the
angle of the text measured in tenths of degrees (for example a value of
150 means 15 degrees).
The following function returns the handle of a font with the same
characteristics of the font whose handle is passed as parameter, but it
allows setting its angle and quality.
interface
uses Windows;
function CreateAngledFont(Font: HFont; Angle: Longint;
Quality: byte = PROOF_QUALITY): HFont;
implementation
function CreateAngledFont(Font: HFont; Angle: Longint;
Quality: byte): HFont;
var
FontInfo: TLogFontA; // Font information structure
begin
// Get the information of the font passed as parameter
if GetObject(Font, SizeOf(FontInfo), @FontInfo) = 0 then begin
Result := 0;
exit;
end;
// Set the angle
FontInfo.lfEscapement := Angle;
FontInfo.lfOrientation := Angle;
// Set the quality
FontInfo.lfQuality := Quality;
// Create a new font with the modified information
// The new font must be released calling DeleteObject
Result := CreateFontIndirect(FontInfo);
end;
We can use this function in a procedure that displays rotated text on
any canvas, including for example the canvas of a printer:
uses Graphics, Windows;
procedure TextOutA(Canvas: TCanvas; X, Y, Angle: Integer;
Text: string);
var
OriginalFont, AngledFont: HFont;
begin
// Create an angled font from the current font
AngledFont := CreateAngledFont(Canvas.Font.Handle, Angle);
if AngledFont <> 0 then begin
// Set it temporarily as the current font
OriginalFont := SelectObject(Canvas.Handle, AngledFont);
if OriginalFont <> 0 then begin
// Write the text
Canvas.TextOut(X, Y, Text);
// Restore the original font
if SelectObject(Canvas.Handle, OriginalFont) = 0 then begin
Canvas.Font.Handle := AngledFont;
// raise Exception.Create('Couldn''t restore font');
exit;
end;
end;
// Release the angled font
DeleteObject(AngledFont)
end;
end;
Here's an example of use:
procedure TForm1.FormPaint(Sender: TObject);
begin
Font.Name := 'Arial'; // IMPORTANT: True Type Font
Font.Size := 14;
Canvas.Brush.Color := Color;
TextOutA(Canvas, 10, 40, 150, 'Hello world!');
end;
If we want we can assign the handle of an angled font to the Handle
property of a TFont object. The handle will be deleted automatically
when this object is destroyed.
The following example uses this technique to draw the items of a
listbox:
procedure TForm1.FormCreate(Sender: TObject);
begin
// Set the font of the listbox to have a 10-degree inclination
with ListBox1.Font do Handle := CreateAngledFont(Handle, 100);
end;
procedure TForm1.ListBox1DrawItem(Control: TWinControl;
Index: Integer; Rect: TRect; State: TOwnerDrawState);
const
TopOffset = 16;
begin
with (Control as TListBox).Canvas do begin
FillRect(Rect);
TextOut(Rect.Left + 2, Rect.Top + TopOffset,
TListBox(Control).Items[Index]);
end;
end;
________________________________________________________________________
3. BORDERWIDTH - ERROR IN COMPONENTS PROPERTY
By Vladimir S. <shvetadvipa@mtu-net.ru>
If you wish to use the BorderWidth property be careful. It's very
strange, but Borland made a mistake in almost all components that have
this property. For example look at the picture (border.gif). You can
see ProgressBars with various BorderWidth values. The height of the
ProgressBars in all cases is 16.
If you wish to correct this error see this example for a ProgressBar.
You have to make changes in COMCTRLS.PAS like this:
interface
...
TProgressBar = class(TWinControl)
private
...
FBorderWidth: TBorderWidth;
...
procedure SetBorderWidth(Value: TBorderWidth);
...
published
...
property BorderWidth: TBorderWidth read FBorderWidth
write SetBorderWidth;
...
...
implementation
...
constructor TProgressBar.Create(AOwner: TComponent);
begin
...
FBorderWidth := inherited BorderWidth;
...
end;
procedure TProgressBar.SetBorderWidth(Value: TBorderWidth);
begin
if Value > (Height div 2)-3 then
raise Exception.CreateFmt('Error: BorderWidth have to less %d',
[(Height div 2)-3]);
if Value <> inherited BorderWidth then begin
inherited BorderWidth := Value;
FBorderWidth := inherited BorderWidth;
end;
end;
...
You can use this patch in all the components that have a BorderWidth
property.
________________________________________________________________________
4. WORKSHOP
In the 16th issue of this newsletter I proposed the creation of a
TDBGrid descendant capable of showing checkboxes for boolean fields, and
I promised to publish the solutions that I get in the first issue of
March, i.e. in this issue. Armando Arias subclassed not only a DBGrid,
but also other components, and even included a package file. Good work.
You can see them in the archive that accompanies this newsletter, which
includes a little demo. It's almost all in Spanish, but maybe seeing the
example you can get an idea of what it does...
________________________________________________________________________
YOU CAN HELP US
We need your help to keep this newsletter going and growing. You can
help by referring the newsletter to your colleagues:
http://www.latiumsoftware.com/en/pascal/delphi-newsletter.php
Or you can help by voting for us in some or all of these rankings to
give more visibility to our web site and thus increase the number of
subscriptions to this newsletter:
http://www.programmingpages.com/?r=latiumsoftwarecomenpascal
http://top100borland.com/in.php?who=20
It's just a few seconds for you that REALLY mean a lot to us.
________________________________________________________________________
If you haven't received the full source code examples for this issue,
you can get them from http://www.latiumsoftware.com/en/file.php?id=p18
________________________________________________________________________
This newsletter is provided "AS IS" without warranty of any kind. Its
use implies the acceptance of our licensing terms and disclaimer of
warranty you can read at http://www.latiumsoftware.com/en/legal.php
where you will also find a note about legal trademarks. Articles are
copyright of their respective authors and they are reproduced here with
their permission. You can redistribute this newsletter as long as you do
it in full (including copyright notices), without changes, and gratis.
________________________________________________________________________
Main page: http://www.latiumsoftware.com/en/pascal/delphi-newsletter.php
Group home page: http://groups.yahoo.com/group/pascal-newsletter/
Subscribe/join: pascal-newsletter-subscribe@yahoogroups.com
Unsubscribe/leave: pascal-newsletter-unsubscribe@yahoogroups.com
Problems with your subscription? eds2008 @ latiumsoftware.com
________________________________________________________________________
Latium Software http://www.latiumsoftware.com/en/index.php
Copyright (c) 2001 by Ernesto De Spirito. All rights reserved.
________________________________________________________________________
|