Delphi Inspect, simple free tool to view FireMonkey and RTL System parameters.

Icon_144

NEW: Updated version compiled with Embarcadero Studio XE 10.1 Berlin “Update 1” (September 2016).

This small app shows a very big quantity of global parameters (variables, class variables, class properties, “service managers” interface values)  from Delphi RTL System units, FireMonkey classes and platform-specific parameters (Android, iOS, Mac OSX and Windows x86 and x64).

https://play.google.com/store/apps/details?id=com.steema.Delphi_Inspect

It also includes benchmarks for the TCanvas graphical methods to test the GPU speed of your Android / iOS mobile device, and Windows / Mac desktop graphics card, as well as basic system benchmarks (TObject, Math, Arrays, I/O) and the new TParallel threading multi-cpu class in XE7.

 

Screenshot_2014-07-31-17-28-38  Screenshot_2014-08-04-13-08-39 Screenshot_2014-08-04-13-08-19

 

The very same source code compiles for Windows x86 32bit, x64, Mac OSX, iOS and Android.

Source code for Embarcadero RAD Studio:

Download Latest version  v6.0 Sep-29th 2016

Older version for XE5 and XE6: Download

Usage:

1
2
3
4
5
6
7
8
9
10
11
Uses InspectDelphi;
 
var s : TStringList;
 
s:=TStringList.Create;
 
TInspectDelphi.AddAll(s);
 
.... do your work with "s" ....
 
s.Free;
Uses InspectDelphi;

var s : TStringList;

s:=TStringList.Create;

TInspectDelphi.AddAll(s);

.... do your work with "s" ....

s.Free;

 

TeeChart and system Styles / Themes. (VCL and Firemonkey)

Next coming TeeChart update will include a new small “Theme” class to use the color settings from the current Application style (VCL and Firemonkey).

(Application styles are available in RAD Studio XE3 and up).

TeeChart_VCL_Style_Light    TeeChart_VCL_Style_Metropolis_Green    TeeChart_VCL_Style_Ruby_Graphite   TeeChart_FMX_Style_Mac_Diamond

The code to enable this automatic chart styling is:

VCL:

uses VCLTee.TeeThemes;
TSystemTheme.ApplyStyle( Chart1 );

Firemonkey:

uses FMXTee.TeeThemes;
TSystemTheme.ApplyStyle( Chart1 );

 

Download:  (Not ready yet until update release)

Small VCL and FMX demos showing how to change the application style at runtime, and then using TeeChart TSystemTheme to apply the current style to a chart.   (For RAD Studio XE3 and up)

 

Notes:

The chart Series ColorPalette is left untouched when applying a system style. It can always be changed using the Chart1.ColorPaletteIndex property or TColorPalettes class methods.

For VCL styles, Font properties (Name, Font Style and Font Size) aren’t applied as there is no easy way to obtain them.  Hope this will be implemented in future updates.

The Chart background and Walls.Back Gradient is disabled when applying a system style, to enable the background color.

 

For more information about RAD XE / Delphi styles:

VCL: Rodrigo Ruz “The Road to Delphi”

Firemonkey: FMX Express Styles

 

New SeriesRegion tool for TeeChart Java

The majority of TeeChart versions already include a tool called SeriesRegion; the time for TeeChart Java to make a step forward has arrived!

To make this tool available you only have to include the according import:

import com.steema.teechart.tools.SeriesRegion;

Then, to use it you only need a chart and a series to link it:

Line line1 = new Line(chart1.getChart());
line1.fillSampleValues(20);

SeriesRegion seriesRegionTool1 = new SeriesRegion(chart1.getChart());
seriesRegionTool1.setSeries(line1);

Other properties this tool includes are AutoBound, UseOrigin, Origin, LowerBound, UpperBound and DrawBehindSeries. You can use the getters and setters to retrieve or set their values. Here a short description of their purpose:

  • AutoBound: If true, region left and right bounds are equal to series minimum and maximum x value.
  • Origin: Region bottom or upper limit. Used only if UseOrigin is true.
  • UseOrigin: If true, region bottom or upper limit is defined by Origin.
  • LowerBound: Defines region left (series not mandatory values) lower bound.
  • UpperBound: Defines region right (series not mandatory values) upper bound.
  • DrawBehindSeries: If true, draw region behind series. If false, draw region over series.

Also note you can access its Brush and Pen like with the other tools inheriting from Tool class.

Playing with this tool and its properties, you can get something like in the image below, extracted from the Features Demo:

SeriesRegion

This tool and the respective demos will be included with the next maintenance release of TeeChart Java (both Swing and SWT) and TeeChart Java for Android.

Converting VCL/FMX and ActiveX templates to .NET.

Over the years, a number of TeeChart users have asked how to convert the charts they created either using TeeChart VCL/FMX or ActiveX to the .NET version, enabling them to more easily port their previously created charting projects to .NET.

Well, this is possible! It might not be the ideal or perfect solution but it’s an approximation that can save you some work. This can be achieved in two ways:

  1. Using the TeeToTen application. It is a .NET application that uses TeeChart ActiveX to load the .tee files (TeeChart VCL/FMX and ActiveX templates), convert them to text files, generate an XML file with series and data and then load them into a .NET chart  which is then used to generate the .ten file (TeeChart .NET templates) file. The tool comes with a readme.txt document that explains which are its prerequisites and how to use it. TeeToTen tool can also be called via command line with several parameter options. This way it can be called from your applications to obtain a completely automatic conversion. Full details on how to use it are available at included readme.txt.
  2. This solution by-passes the ActiveX version and uses TeeToText, a small VCL application that loads .tee files and generates the necessary text and XML files. Actually, anybody that uses TeeChart VCL/FMX or TeeChart ActiveX can easily generate such files using their built in exporting functionalty, which is what TeeToText does. Once the process is complete,  you need to use TenCreator.dll included with TeeToTen  to import these generated files into your .NET chart. Here’s an example of TenCreator.dll being used to convert one file:
1
2
3
4
5
6
7
8
string chartFile = @"C:\temp\TemplateSamples\Annotations.txt";
string dataFile = @"C:\temp\TemplateSamples\Annotations.xml";
 
TenCreator.TenStreamer streamer = new TenCreator.TenStreamer();
System.IO.Stream netStream = streamer.ConvertFile(chartFile, dataFile);
netStream.Position = 0;
tChart1.Import.Template.Load(netStream);
tChart1.Export.Template.Save(@"C:\TemplateSamples\Annotations.ten");
string chartFile = @"C:\temp\TemplateSamples\Annotations.txt";
string dataFile = @"C:\temp\TemplateSamples\Annotations.xml";

TenCreator.TenStreamer streamer = new TenCreator.TenStreamer();
System.IO.Stream netStream = streamer.ConvertFile(chartFile, dataFile);
netStream.Position = 0;
tChart1.Import.Template.Load(netStream);
tChart1.Export.Template.Save(@"C:\TemplateSamples\Annotations.ten");

and here’s an example converting a complete folder:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
public Form1()
{
InitializeComponent();
InitializeChart();
}
 
private void InitializeChart()
{
DirectoryInfo dFolder = new DirectoryInfo(@"C:\TemplateSamples\");
SearchOption so = new SearchOption();
bool incSubDirectories = false;
 
if (incSubDirectories)
{
so = SearchOption.AllDirectories;
}
else
{
so = SearchOption.TopDirectoryOnly;
}
 
FileInfo[] fFileArray = dFolder.GetFiles("*.tee", so);
 
foreach (FileInfo fFile in fFileArray)
{
ConvertFile(fFile.FullName);
}
}
 
private void ConvertFile(string fileName)
{
string chartFile = fileName.Replace(".tee", ".txt");
string dataFile = fileName.Replace(".tee", ".xml");
 
TenCreator.TenStreamer streamer = new TenCreator.TenStreamer();
Stream netStream = streamer.ConvertFile(chartFile, dataFile);
netStream.Position = 0;
tChart1.Import.Template.Load(netStream);
tChart1.Export.Template.Save(fileName.Replace(".tee", ".ten"));
}
public Form1()
{
InitializeComponent();
InitializeChart();
}

private void InitializeChart()
{
DirectoryInfo dFolder = new DirectoryInfo(@"C:\TemplateSamples\");
SearchOption so = new SearchOption();
bool incSubDirectories = false;

if (incSubDirectories)
{
so = SearchOption.AllDirectories;
}
else
{
so = SearchOption.TopDirectoryOnly;
}

FileInfo[] fFileArray = dFolder.GetFiles("*.tee", so);

foreach (FileInfo fFile in fFileArray)
{
ConvertFile(fFile.FullName);
}
}

private void ConvertFile(string fileName)
{
string chartFile = fileName.Replace(".tee", ".txt");
string dataFile = fileName.Replace(".tee", ".xml");

TenCreator.TenStreamer streamer = new TenCreator.TenStreamer();
Stream netStream = streamer.ConvertFile(chartFile, dataFile);
netStream.Position = 0;
tChart1.Import.Template.Load(netStream);
tChart1.Export.Template.Save(fileName.Replace(".tee", ".ten"));
}

This project is a work in progress. It’s being improved upon user demand so feel free to let us know your feedback at info at steema dot com.  We hope this helps in the transition of your existing projects that use TeeChart to the .NET platform.

 

TeeChart WPFDirect2D Beta

wpfvswpfdirect2D
Screenshot of FastLineWPF_Speed demo app

I’m pretty excited to announce the public availability of TeeChart.WPFDirect2D.dll, a new assembly in the TeeChart for .NET family. This assembly functions with SlimDX to produce a seamless Direct2D experience within the WPF framework, producing increases of rendering performance by at least a factor of two (>=200%). The binary version of a demo app which includes the TeeChart.WPFDirect2D.dll can be downloaded from here, while the source code for that same demo is available here.

Using Themes with TeeChart

Introduction

 

“Themes” allow changing all visual formatting properties of Charts with a single click or line of code.

The default look of a TeeChart hasn’t been changed for many years. This is on purpose, as it might be annoying to discover existing charts have  completely different colors or font styles just because a new version has been installed.

 

Default TeeChart Theme

Time goes fast, and what it looked “modern” in the past, might look “old fashioned” in the future.  (If we wait a little bit more, maybe the old look will be modern again. Trends are cycling  :-).

 

Choosing a Theme

 

The chart editor dialog (in the “Pro” version of TeeChart) includes a Theme tab where you can choose and apply a Theme both at design-time and run-time:

TeeChart Themes Editor

 

 

Clicking the bottom-right “Apply” button will change all necessary properties in the edited chart, like fonts, colors, pens and brushes.

 

 

Applying Themes by code

 

Adding the Themes unit to the “uses” clause ( VCLTee.TeeThemes or FMXTee.Themes) enables using the predefined theme classes or creating custom themes.

The above picture shows the “Flat” theme selected in the editor. This is just a small class named “TFlatTheme”, derived from a base TChartTheme class.

Applying the Flat theme at runtime by code:

uses VCLTee.TeeThemes; // FMXTee.Themes <--- FireMonkey

ApplyChartTheme( TFlatTheme, Chart1 );

 

Available Themes

 

There are several theme classes included in the Themes unit.

A list of themes can be obtained with the global ChartThemes variable. Each item in the list is a TChartTheme class that can be passed to ApplyChartTheme method.  This is the list displayed at the above Themes editor dialog.

 

Creating custom Themes

 

Customizing a theme to apply it to other charts is really easy.
A “theme” is nothing more, and nothing else, than a normal Chart.

That means, any existing chart can be used as a theme for any other chart.

For example, the chart below (“BlueChart”) has been manually customized in a couple of minutes, changing font styles to “Segoe UI”, changing the panel color to white, setting series color and border color to blue, hidding the axes ticks, etc.

 

TeeChart Custom Theme

 

This chart can now be used as a new custom Theme, for example to change the look of the above first chart with this simple code:

// Apply ( Destination Chart  <----  Origin Chart )

TThemesList.Apply( Chart1, BlueChart );

 

Chart1 (the first chart in this post), has now been changed to:

 

TeeChart_with_custom_Theme

 

Note in the above chart that when applying a theme, properties that affect the appearance are the only ones modified. This includes font styles, colors and transparencies.  Visibility of elements (chart legend, series marks, 3D etc) are left unchanged.

 

Data Color Palette

 

Colors used to fill individual series points (like the colors for the above Bar items) are chosen from a color palette.  This is essentially an “Array of TColor”.

TeeChart includes several predefined color palettes. Each palette is identified by a number.  The list of available palettes is located at the chart editor “General -> Palette” tab:

TeeChart_Color_Palettes

 

 

This dialog allows changing the predefined color palette or creating custom palettes. Colors can be clicked to change them, and the buttons allow adding,  removing or reordering colors.

Changing a color palette by code is just changing a chart property:

// Predefined palettes, from 1 to 19

Chart1.ColorPaletteIndex := 5 ;

 

An array of colors can also be used as a palette:

 

procedure TForm1.Button4Click(Sender: TObject);
const
  MyColors : Array[0..7] of TColor = (
    $FF0000,
    $0000FF,
    $00FF00,
    $00CCFF,
    $404040,
    $00FFFF,
    $C000FF,
    $FFFFFF );

begin
  TColorPalettes.ApplyPalette( Chart1, MyColors );
  Chart1.Invalidate;
end;

 

Color palettes and themes are totally independent. Applying a theme to a chart will replace the chart colors with the theme colors (a theme is just a normal chart).

After applying a theme, the color palette can be changed at any time.

 

 

Registering Custom Themes

 

(Advanced)

Custom themes (charts that can be used as themes for other charts) can also be “registered” with the purpose of showing them at the Themes Editor list.

This is done with the help of small class derived from base TChartTheme:

type
  TMyBlueTheme=class(TChartTheme)
  public
    procedure Apply; override;
    function Description:string; override;
  end;

procedure TMyBlueTheme.Apply;
var tmp : TForm1;
begin
  inherited;

  tmp:=TForm1.Create(nil);
  try
    TThemesList.Apply(Self.Chart, tmp.Chart2);
  finally
    tmp.Free;
  end;
end;

function TMyBlueTheme.Description:string;
begin
  result:='My Blue Theme';
end;

// And then calling a method to register the class:

RegisterChartThemes([TMyBlueTheme]);

This is how existing themes are internally registered.

The Apply method can also be used to perform any additional settings or changing any other property.

 

Download example

 

Click here to download a small VCL example project showing the above code.

Note: The “Pro” version of TeeChart is required.

 

TeeChart and GDI+ inside a DLL

 

TeeChart VCL controls use GDI+ (Windows graphics library) by default in VCL applications.

 

TeeChart GDI+ editor dialog
TeeChart GDI+ editor dialog

 

NOTE: The fix indicated below has been already included in the latest VCL version: 2014.11.140512    Download link

There is a “problem” with GDI+ when using it inside a DLL. GDI+ needs to be initialized before using it, and the initialization should be done by the caller EXE process, not by the DLL itself.

(Microsoft information about this can be found here in this link)

This is why the Embarcadero RAD Studio RTL WinApi.GDIPOBJ.pas unit, at the bottom of the file initialization section, checks “if not IsLibrary” to initialize GDI+ only when the unit is used by an executable application.

The problem is, if you have a DLL that contains chart controls, and if GDI+ has not been correctly initialized, an Access Violation exception will be raised from code inside the Windows GDI+ gdiplus.dll !

The solution is quite easy. In your EXE application, before calling any DLL function, add this code to initialize GDI+ :

uses WinAPI.GDIPObj, WinAPI.GDIPApi ;

// Initialize StartupInput structure
StartupInput.DebugEventCallback := nil;
StartupInput.SuppressBackgroundThread := False;
StartupInput.SuppressExternalCodecs := False;
StartupInput.GdiplusVersion := 1;

GdiplusStartup(gdiplusToken, @StartupInput, nil);

 

It is also recommended (although it doesn’t seem mandatory), to uninitialize GDI+, as one of your EXE last steps:

GdiplusShutdown(gdiplusToken);

 

The next TeeChart release (very soon !) will include a small fix to improve this situation: if GDI+ is not initialized for any reason, it will fallback to “old” GDI graphics instead, avoiding the exception.

Click here to download a simple test project made in Delphi with RAD XE5 that includes an EXE and a DLL. The DLL contains a Form1 with a Chart1. The EXE main unit initializes GDI+ and calls the DLL to show the chart.

 

How to make a transparent chart with TeeChart Pro ActiveX

While part of the Steema team was at the Mobile World Congress and WIPJam events in Barcelona, getting acquainted with the novelties on the mobile sector, some of us remained at the office in Girona working on some vintage stuff, let’s call it.

Over the years, one of  the recurring questions with TeeChart Pro VCL/FMX has been how to create a transparent chart. We have an old Delphi demo project which accomplishes this. It consists of an image in a form and a chart over it. The goal is to make the chart transparent so that the image can be seen through the chart background. This is achieved by first making the chart back wall transparent and then, generating a bitmap the size of the chart from the background image at the chart location and drawing it on the TChart canvas. This process produces a chart like that:

Chart with a transparent background in Delphi.
Chart with a transparent background in Delphi.

which still is an interactive chart which responds to mouse action: clicks, zoom, panning, etc.

Pretty simple in Delphi, huh? Now let’s complicate things a little bit. We were faced with the question of how to do the same with TeeChart ActiveX. Actually, I don’t know why this didn’t come up before or, if it had been asked for, I was not aware of it. Anyway, this wouldn’t have sounded that complicated if it hadnn’t been because it ended up being a Frankenstein project, since it needed to be TeeChart Pro ActiveX in VB.NET. So a nice COM/.NET mix. Well, this may not make a Frankenstein but wait, the sophistication doesn’t end here. As you may already know, TeeChart Pro ActiveX is a COM wrapper of the TeeChart Pro VCL/FMX version, so an intriguing mixture of Delphi (VCL) code with ActiveX objects and .NET methods/properties. It doesn’t sound  that straightforward now, does it?

Ok, let’s break things into different parts and will see how the original Delphi code was literally ported to VB with TeeChart ActiveX. First of all, setting the chart panel to be transparent gets somewhat complicated when mixing ActiveX and .NET worlds:

AxTChart1.Panel.Color = Convert.ToUInt32(ColorTranslator.ToOle(Color.Transparent))

That tricky conversion is the only remarkable part of initial chart settings. The substantial code is in the OnBeforeDrawChart event though. That’s how it looks like in Delphi:

procedure TForm1.Chart1BeforeDrawChart(Sender: TObject);
begin
	if not Assigned(Back) then
	begin
		Back:=TBitmap.Create;
		Back.Width:=Chart1.Width;
		Back.Height:=Chart1.Height;

		Back.Canvas.CopyRect(Chart1.ClientRect,Canvas,Chart1.BoundsRect);
	end;

	if Chart1.Color=clNone then
		Chart1.Canvas.Draw(0,0,Back);
end;

All that fuss for about 10 lines of code!? Well, first I should admit that Steema’s .NET language of choice is C#. So I have some difficulties converting C# to VB. Luckily, most of them are solved using Carlos Aguilar’s VB to (and from) C# code translator. You’ll also notice that I’m not an expert on code formatting in WordPress either. I must admit this is my very first article and found that Posting Source Code suggested solution doesn’t work very well for me. I hate poorly indented code so any help on this will be appreciated.

Ok, back on track, I needed to find out which is the equivalent method of Delphi’s CopyRect, which basically copies a part of an image into another image canvas. This can be done with System.Drawing.Graphics.DrawImage method. It has several overloads so I had to find out the one that does the same as CopyRect in Delphi. The most similar overload I could find is this. With a little help from a search engine I found that that simple Delphi call would turn out to be another 10 line method in VB:

Private Function CopyRect(ByVal srcBitmap As Bitmap, _
	ByVal destRect As Rectangle, ByVal srcRect As Rectangle) As Bitmap

	' Create the new bitmap and associated graphics object
	Dim bmp As New Bitmap(srcRect.Width, srcRect.Height)
	Dim g As Graphics = Graphics.FromImage(bmp)

	'Draws the specified portion of the specified Image at the specified location and with the specified size.
	g.DrawImage(srcBitmap, destRect, srcRect, GraphicsUnit.Pixel)

	' Clean up
	g.Dispose()

	' Return the bitmap
	Return bmp
End Function

It would look like I was halfway done but I found that I was completely wrong. ActiveX controls don’t have ClientRect property that Delphi controls have. I also had to manually create BoundsRect. Nothing complicated but something the almighty Delphi also did for me:

Dim ClientRect As Rectangle = New Rectangle(0, 0, AxTChart1.Width, AxTChart1.Height)
Dim ChartBounds As Rectangle = New Rectangle(AxTChart1.Location.X, AxTChart1.Location.Y, _
											 AxTChart1.Width, AxTChart1.Height)

So now that all the elements are in place, I just needed to paint the resulting bitmap to TeeChart’s canvas. But wait, another ActiveX vs .NET trick was still waiting for me. Calling Canvas.Draw on TeeChart ActiveX with a .NET Framework native System.Drawing.Bitmap was showing a warning about an image format conversion issue. Besides of that, I decided to go ahead but the warning turned to a run-time error. I had to convert the .NET bitmap to a stdole.IPictureDisp. Thanks to this article I learned that I had to create an additional class derived from AxHost to have access to some private methods of this class that would do the conversion for me. I copied the class, converted it to VB with the mentioned code translator and I was all set to paint the image into TeeChart’s canvas:

If AxTChart1.Panel.Color = Convert.ToUInt32(ColorTranslator.ToOle(Color.Transparent)) Then
	Dim backImage As stdole.IPictureDisp = AxHostConverter.ImageToPictureDisp(Back)
	AxTChart1.Canvas.Draw(0, 0, backImage)
End If

Now all code was complete and I could run and see the result. I went for it and, to my deception, I found that the image from the picture box was always in the original size; it didn’t come out with the stretching method I was using:

PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage

Once again, Delphi handled this nicely without having to implement any additional code. So, time to scratch my head a little bit more and thanks to internet, I found that I had to create an intermediate image with the stretched image dimensions which resulted in this method:

Private Function GetStretchedImage(ByVal image As Image) As Bitmap
	If PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage Then
		Dim bmp As Bitmap = New Bitmap(PictureBox1.Width, PictureBox1.Height)

		Dim g As Graphics = Graphics.FromImage(bmp)
		g.InterpolationMode = Drawing2D.InterpolationMode.NearestNeighbor
		g.DrawImage(image, New Rectangle(Point.Empty, bmp.Size))

		Return bmp
	Else
		Return image
	End If
End Function

Phew! This finally produced the result I expected and what was so simple to do in Delphi:

TransparentActiveXNET

Didn’t I tell you it was some sort of Frankenstein example? If you are interested in seeing all the nuances in detail you can download the complete project. You’ll need TeeChart Pro ActiveX 2014 to run it. A fully functional evaluation version can be download at the TeeChart ActiveX downloads page.

Welcome to Steema blogs

Hi, Welcome to Steema Blogs!

These pages are intended to bring together comments and articles from various contributors in the Steema team with the goal of  1) adding value to the basic information beyond the standard Steema newsfeed, forums and product documentation and 2) to humanise a little the interface that our web presence presents to the “inter-world”.

Thanks!

Steema team!