Frequently Asked Component Specific Questions
Options |
|
Display all FAQ items |
Displaying items 721 to 735 of 888, page 49 of 60
<< previous next >>

TMS VCL ChartRetrieving the serie values at crosshair
While the tracker window will display serie values at crosshair position, it can often be interesting to retrieve the values in code. Following code snippet shows the serie values in the caption of the form:
procedure TForm1.AdvChartView1MouseMove(Sender: TObject; Shift: TShiftState;
X, Y: Integer);
var
i: integer;
cp: TChartPoint;
s: string;
begin
with AdvChartView1.Panes[0] do
begin
s := '';
for i := 0 to Series.Count - 1 do
begin
cp := GetChartPointAtCrossHair(i);
if s = '' then
s := floattostr(cp.SingleValue)
else
s := s + ':' + floattostr(cp.SingleValue);
end;
end;
end;
TAdvPanelProgrammatically adding and removings panels in TAdvPanelGroup
It is simple to programmatically add a TAdvPanel to a TAdvPanelGroup. Three methods are available for this:
- AdvPanelGroup.AddPanel: TAdvPanel; adds a panel on top of existing panels in the group
- AdvPanelGroup.InsertPanel(index: Integer): TAdvPanel; inserts a panel at position index in the group
- AdvPanelGroup.AppendPanel: TAdvPanel; adds a panel at last position in a group
with AdvPanelGroup1, AdvPanelGroup1.AppendPanel do begin Text := 'panel'+inttostr(PanelCount); Caption.Visible := true; Caption.Text := 'Programmatically inserted panel'; Caption.MinMaxButton := true; end;
begin AdvPanelGroup1.RemovePanel(0); end;
This code snippet moves the last panel to the first position:
begin AdvPanelGroup1.MovePanel(AdvPanelGroup1.PanelCount - 1,0); end;

TMS Advanced Toolbars & MenusProviding an Office 2007 type hint for any control
The TMS components that have built-in support for Office 2007 type hints expose the property OfficeHint with which the hint title, notes, picture and help line can be set. If you want to use an Office 2007 for another standard VCL component or other 3rd party component, you can use the event AdvOfficeHint.OnBeforeShowHint. This sample demonstrates how this can be done. Via the event handler, an Office 2007 hint is set for a TAdvSmoothButton:
procedure TForm1.AdvOfficeHint1BeforeShowHint(Sender: TObject;
AControl: TControl; AHintInfo: TAdvHintInfo; var UseOfficeHint: Boolean);
begin
if AControl = AdvSmoothButton1 then
begin
UseOfficeHint := true; // set true to tell the TAdvOfficeHint it should display the hint in Office 2007 style
AHintInfo.Title := 'Button title';
AHintInfo.Notes.Text := AControl.Hint;
AHintInfo.Picture.LoadFromFile(''); // optionally add a hint picture here from file, resource or stream
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
// set the standard Hint to make sure it shows, this is reused as hint notes
AdvSmoothButton1.Hint := 'Smooth button hint';
end;
TAdvEditAllowing to enter negative & positive numbers
Set AdvEdit.EditType = etNumeric; Set AdvEdit.Signed = true;

TMS VCL ChartProgrammatically scrolling and zooming in the chart
Scrolling and zooming via code in the chart is simple. This is just a matter of programmatically changing the properties Pane.Range.RangeFrom and Pane.Range.RangeTo. To illustrate this, we create a single sinus serie in a chart and add 4 buttons to control the scrolling & zooming:
Initialization of the chart:
procedure TForm1.FormCreate(Sender: TObject);
var
i: integer;
begin
advchartview1.BeginUpdate;
advchartview1.Panes.Clear;
advchartview1.Panes.Add;
advchartview1.Panes[0].Options := advchartview1.Panes[0].Options + [poMoving, poHorzScroll, poHorzScale];
advchartview1.Panes[0].Series.Add;
with advchartview1.Panes[0].Series[0] do
begin
for i := 1 to 200 do
AddSinglePoint(50 * sin(i/20*PI));
end;
advchartview1.Panes[0].Series[0].AutoRange := arCommon;
advchartview1.Panes[0].Range.RangeFrom := 0;
advchartview1.Panes[0].Range.RangeTo := 200;
advchartview1.EndUpdate;
end;procedure TForm1.Scroll(delta: integer); begin advchartview1.BeginUpdate; advchartview1.Panes[0].Range.RangeFrom := advchartview1.Panes[0].Range.RangeFrom + delta; advchartview1.Panes[0].Range.RangeTo := advchartview1.Panes[0].Range.RangeTo + delta; advchartview1.EndUpdate; end; procedure TForm1.Zoom(delta: integer); begin advchartview1.BeginUpdate; advchartview1.Panes[0].Range.RangeFrom := advchartview1.Panes[0].Range.RangeFrom + delta; advchartview1.Panes[0].Range.RangeTo := advchartview1.Panes[0].Range.RangeTo - delta; advchartview1.EndUpdate; end;
procedure TForm1.ScrollLeftClick(Sender: TObject); begin Scroll(-10); end; procedure TForm1.ScrollRightClick(Sender: TObject); begin Scroll(+10); end; procedure TForm1.ZoomOutClick(Sender: TObject); begin Zoom(+10); end; procedure TForm1.ZoomInClick(Sender: TObject); begin Zoom(-10); end;

TMS VCL ChartUsing Y-axis values per serie in the chart
Each serie in the chart can have its own Y-axis values. It can be choosen if the Y-axis values for a series should be displayed left or right from the chart. The settings to control this are under Serie.YAxis.Position. When two series have an Y-axis displayed on the same size of the chart, the spacing between the Y-axis itself and value is controlled by Serie.YAxis.MajorUnitSpacing := 30;
In the code sample below, 4 series are added to the chart. Series 1 and 3 have the Y-axis on the left side while series 2 and 4 have the Y-axis on the right side. To make clear what Y-axis belongs to what series, the serie line color is set to the same color as the Y-axis value font.
procedure TForm2.InitChart;
begin
advchartview1.BeginUpdate;
advchartview1.Panes[0].Series.Clear;
with advchartview1.Panes[0].Series.Add do
begin
YAxis.Position := yLeft;
YAxis.MajorUnitSpacing := 30;
YAxis.MajorFont.Color := clRed;
AddSinglePoint(0);
AddSinglePoint(15);
AddSinglePoint(17);
AddSinglePoint(18);
LineColor := clRed;
AutoRange := arEnabled;
end;
with advchartview1.Panes[0].Series.Add do
begin
YAxis.Position := yRight;
YAxis.MajorUnitSpacing := 30;
YAxis.MajorFont.Color := clGreen;
AddSinglePoint(150);
AddSinglePoint(100);
AddSinglePoint(120);
AddSinglePoint(190);
LineColor := clGreen;
AutoRange := arEnabled;
end;
with advchartview1.Panes[0].Series.Add do
begin
YAxis.Position := yLeft;
YAxis.MajorFont.Color := clBlue;
AddSinglePoint(20);
AddSinglePoint(25);
AddSinglePoint(27);
AddSinglePoint(28);
LineColor := clBlue;
AutoRange := arEnabled;
end;
with advchartview1.Panes[0].Series.Add do
begin
YAxis.Position := yRight;
YAxis.MajorFont.Color := clYellow;
AddSinglePoint(250);
AddSinglePoint(200);
AddSinglePoint(210);
AddSinglePoint(380);
LineColor := clYellow;
AutoRange := arEnabled;
end;
advchartview1.Panes[0].YAxis.Position := yBoth;
advchartview1.Panes[0].YAxis.Size := 150;
advchartview1.Panes[0].Range.RangeFrom := 0;
advchartview1.Panes[0].Range.RangeTo := 3;
advchartview1.EndUpdate;
end;
TMS VCL ChartAdd custom X-axis text programmatically
With the latest version of the TAdvChartView component it is possible to add custom X-Axis text by a new override of the AddSinglePoint method that has a parameter XAxisText.
The sample code snippet here shows how to add a custom numbering as X-axis label text rotated by 40°.
procedure TForm.FormCreate(Sender: TObject);
var
i: integer;
xval: Double;
begin
with AdvChartView1.Panes[0] do
begin
//Set range
Range.RangeFrom := 0;
Range.RangeTo := 100;
Range.MaximumScrollRange := 100;
Range.MinimumScrollRange := 0;
//Set X-Axis size
XAxis.Size := 60;
//Add points with custom X-Axis text
with Series[0] do
begin
ChartType := ctBar;
AutoRange := arEnabledZeroBased;
Color := clBlue;
ColorTo := clSilver;
for I := 0 to 100 do
begin
xval := 144 + (I * 0.2);
AddSinglePoint(RandomRange(20, 100), FloatToStr(xval));
end;
//Rotate text
XAxis.TextBottom.Angle := 40;
//Enabled tickmarks
XAxis.TickMarkColor := clBlack;
end;
end;

TMS VCL ChartAdd custom X-axis values via an event
To override the standard X-axis values drawn by TAdvChartView an event OnXAxisDrawValue event is available for each serie. To add an event handler for OnXAxisDrawValue, declare a procedure and assign it to the serie.OnXAxisDrawValue event like in the code snippet below:
AdvChartView.Panes[0].Series[0].OnXAxisDrawValue := XAxisDrawValue; procedure TForm.XAxisDrawValue(Sender: TObject; Serie: TChartSerie; Canvas: TCanvas; ARect: TRect; ValueIndex, XMarker: integer; Top: Boolean; var defaultdraw: Boolean); begin //Insert Code here end;
The technique illustrated with following sample. Some points were added in a serie and for each odd value on the X-Axis we want to display a Car brand in the X-axis:
procedure TForm.XAxisDrawValue(Sender: TObject; Serie: TChartSerie;
Canvas: TCanvas; ARect: TRect; ValueIndex, XMarker: integer; Top: Boolean;
var defaultdraw: Boolean);
const
lst: array[0..4] of String = ('Audi', 'BMW', 'Mercedes', 'Bugatti', 'Porsche');
var
s: String;
th, tw: integer;
begin
if Odd(ValueIndex) then
begin
Canvas.Font.Size := 12;
s := lst[Random(Length(lst))];
th := Canvas.TextHeight(s);
tw := Canvas.TextWidth(s);
Canvas.TextOut(Xmarker - (tw div 2), ARect.Top + th, s);
end;
end;
TAdvSmoothCalendarGroupAdding a status message for a day
Adding a status message is done by using the event OnDateStatus. In this event, the text can be set for a status message for each day with the parameter StatusMessage. A parameter of this event is Fill and this allows to choose a different appearance from the default status message appearance set by TAdvSmoothCalendar.StatusAppearance.
This code snippet shows how to add a status message for today in the default color and for the 15th of the month in green color:
procedure TForm1.AdvSmoothCalendar1DateStatus(Sender: TObject; Date: TDateTime;
var StatusMessage: string; Fill: TGDIPStatus; var OffsetX, OffsetY: Integer);
var
da,mo,ye: word;
begin
if date = int(now) then
begin
statusmessage := 'Now';
fill.Assign(AdvSmoothCalendar1.StatusAppearance);
end;
decodedate(date, ye, mo, da);
if da = 15 then
begin
statusmessage := 'halfway';
fill.Fill.Color := clLime;
fill.Fill.ColorTo := clGreen;
fill.Fill.ColorMirror := clNone;
fill.Fill.ColorMirrorTo := clNone;
end;
end;
TMS Advanced Toolbars & MenusStarting with TMS ToolBars & Menus to create Office 2003 style applications
- Step 1: Drop one or more TAdvDockPanel components on the form. With the property Align, select on which side of the form the toolbars will be dockable.
- Step 2: Drop a TAdvToolBarOfficeStyler component on the form and assign it to AdvDockPanel.ToolBarStyler
- Step 3: Drop one or more TAdvToolBar components on the TAdvDockPanel. Assign the TAdvToolBarOfficeStyler to the TAdvToolBar.ToolBarStyler property
- Step 4: Right-click the TAdvToolBar and choose to add a button, menubutton or separator or drop any control on the TAdvToolBar

TMS Advanced Toolbars & MenusUsing the TMS TAdvMenus with the TAdvToolBar
- Step 1: Drop a TAdvMainMenu on the form and use the design-time editor to define the menu. Drop a TAdvMenuStyler on the form and assign it to TAdvToolBarStyler.AdvMenuStyler
- Step 2: Remove the Form.Menu property
- Step 3: Assign the TAdvMainMenu to TAdvToolBar.Menu

TMS Advanced Toolbars & MenusStarting with TMS ToolBars & Menus to create Office 2007 style applications
Choose File, New, Other, TMS Wizard, TMS ToolBar Application wizard : A new application with TAdvToolBarPager will be created

TMS Advanced Toolbars & MenusHandling shortcuts
As menus are assigned to a toolbar and not to a form and the form is responsible for shortcut handling, the TAdvToolBar's shortcuts can be handled by adding the following code in the form's OnShortCut event:
procedure TForm1.FormShortCut(var Msg: TWMKey; var Handled: Boolean); begin Handled := AdvToolBar1.IsShortCut(Msg); end;

TMS Advanced Toolbars & MenusUpgrading from TAdvToolBar v1.x
Make sure to FIRST reopen ALL form files in your application that use the TAdvToolBar and/or TAdvToolBar styler components, ignore all property errors upon opening the forms and save the form files before rebuilding your application.

TMS Advanced Toolbars & MenusUsing menu items with Notes
A menu item with a Notes text can be setup using \n to separate lines, ie
MenuItem.Caption := 'MenuCaption\nLine 1 of the notes text\nLine 2 of the notes text';