How to add values to an exisiting TPieSeries via Delphi Xe7 - delphi

As the title suggest, how can I add a value to an already existing pie slice in a TPieseries within the TChart component.
delphi XE7 for iOS FMX

Access the indexed values through the TPieSeries.PieValues property.
Make an addition with the existing value. You can preinitialize the pie values with zero.
Series1.PieValues[2] := Series1.PieValues[2] + 10;
A better approach is to accumulate the values before adding them into the chart.

Related

Style individual Labels on Gantt-Rows in a VCL TeeChart

I am using TeeChart (Build 2020.30.200525) in a Delphi XE3 VCL-Application.
In that application I am setting up a Gantt series and I would like to style an individual row label on the left axis to set it apart from the others.
Something like changing the color or font-style of the label or highlighting it by using a background.
How could I achieve this?
I have found the OnGetAxisLabel event which I ca use to change the text of the labels.
And I have also tried Axes.Left.Items, but that only has a single element even after I have added several Values to the Gantt-Series.
You need to force a chart repaint to populate the axis items. Ie:
uses VclTee.GanttCh;
procedure TForm1.FormCreate(Sender: TObject);
begin
Chart1.AddSeries(TGanttSeries).FillSampleValues;
Chart1.Draw; // Force a repaint to populate Axis Items
Chart1.Axes.Left.Items.Automatic:=False;
Chart1.Axes.Left.Items[2].Format.Font.Color:=clRed;
end;

Change color in tcxgrid column in delphi?

I have two grids:
in one form and compare between two value I need to change the color of the column in the grid when the two values are not equal
TotalYear:=0 ;
while not (mTblDetail.eof) do
begin
TotalYear:=TotalMonth +mTblDetail.FieldByName('Target_').AsFloat;
mTblDetail.Next;
end;
TotalMonth:=0;
while not(DataSet.Eof) do
begin
TotalMonth:=TotalMonth+DataSet.FieldByName('Target_').AsFloat;
DataSet.Next;
end;
I need to compare the two values and change the color
if(TotalYear<>TotalMonth) then
I tried to use this :
DataSet.Columns[8].Color:= clRed
but is displays an error "Not Accepted". How Can change the color of a column of a Tcxgrid?
Coloring in cxGrids is best done via cxStyles. Drop a TcxStyleRepository on the form and add some styles. You can assign them to the View.Styles.* properties or via events like OnGetContentStyle. I'm sure the online help contains an overview with screenshots and examples.

How to change the color of a FM TSpeedButton

My Application has several TSpeedButtons with which to choose a color and I want each choice to be shown by the color of the TSpeedButton.
I found this answer on Stackoverflow on how to change the color of a TButton. The second answer (change colors dynamically) appears to be the solution I am looking for. It reads as follows:
var r: TRectangle;
begin
// Find the background TRectangle style element for the button
r := (Button1.FindStyleResource('background') as TRectangle);
if Assigned(r) then
begin
r.Fill.Color := claBlue;
end;
end;
This does not work anymore (i use XE5, this is XE2?). It generates an exception at the r := ... statement with:
"illegal cast".
The FindStyleResource returns a FMXObject.
TRectangle is a TShape->TControl->TFMXObject.
I can cast to TControl but not to TShape. In case you wonder, Button1 is a TButton.
Does anyone know how I do change the color of a TSpeedButton?
As an aside: is there a way to determine which type of object exactly is beging returned? I couldn't find out in the debugger.
The answer to the question you linked to relates to vector styles, where the style constructed entirely from shapes etc (such as the TRectangle).
In newer versions of FireMonkey the 'system' styles (which mimic the OS look) and some other styles use bitmaps.
If you want to edit a bitmap style, you'll need to find the bitmap image in the style, edit it, and then redo/edit the button's style to use the new image. (If you're on mobile this will probably be hard enough that you shouldn't even try it).
Another route would be be to change to one of the bitmap styles supplied with Delphi. You will find them under the redist/styles/fmx folder of your Delphi installation.
As for the class of the object, and as per other comments, examine the ClassName property of the object returned.
But bear in mind that not every style will have an object called 'background'. Both the name of the object and it's class can easily vary between styles. You really ought to look at the style you want to pluck objects from to see what's there. (Note that the objects name ('background') will be in the StyleName property).
It would be much easier to use a TColorButton instead, which directly exposes the Color property. You can find it on the Colors page of the component palette. Here are two on a new FMX form in the IDE's form designer:
As far as "which type of object is being returned", you can use the debugger or a ShowMessage for the TFMXObject.ClassName of the return value:
var
Obj: TFmxObject;
begin
Obj := Button1.FindResource('background');
if Assigned(Obj) then
ShowMessage(Obj.ClassName);
end;

Shifting the erroneous horizontal position of SubItemImages in a Delphi TListView?

In a Delphi TListView, is it possible to shift the erroneous horizontal position of SubItemImages, as they are drawn too far left? Something like this, for example (pseudo-code, which just shows the intention):
x := MyListView.Items[i].SubItemImages[2].HorizontalPosition;
MyListView.Items[i].SubItemImages[2].HorizontalPosition := x + 2;
This screenshot which shows the bug:
No. TListItem.SubItemImages is an integer, and integers don't have horizontal positions.
property SubItemImages[Index: Integer]: Integer read GetSubItemImage
write SetSubItemImage;
You can find this out by looking at the VCL source code, in this case in the ComCtrls unit. The relevant code is in TListItem.GetSubItemImage (code from XE3 shown below, but it's the same as the code in previous versions of Delphi).
function TListItem.GetSubItemImage(Index: Integer): Integer;
begin
Result := TSubItems(FSubItems).ImageIndex[Index];
end;
As far as I can see from the MSDN documentation, there's no way to change that image's location. The columns are created by sending the underlying Windows ListView control an LVCOLUMN record (structure) for each column's definition, which has no location information available to assign. It has a flag to set the image right-aligned (LVCFMT_BITMAP_ON_RIGHT), but nothing else to allow you to actually position the image to a specific location in the column.

What is the normal colo(u)r of a selected stringgrid row?

I am overriding OnDrawCell for a string grid. In certain circumstance, I want to use the normal TColor that is used for the selected row when the system does the drawing (no OnDrawCell).
Which colo(u)r is that? clXXX ?
Before of Delphi 2010 you can use the clHighlight color.
In Delphi 2010 the TStringGrid, TDrawGrid and TDBGrid components now have a DrawingStyle property and depending of this value (gdsClassic, gdsGradient, gdsThemed) you must calculate the color on this way.
1.for gdsClassic use clHighlight;
2.for gdsGradient use the GradientFillCanvas method
GradientFillCanvas(Canvas, GetShadowColor(clHighlight, 45), GetShadowColor(clHighlight, 10), LRect, gdVertical);
3.for gdsThemed call the DrawElement method of the TCustomStyleServices
StyleServices.DrawElement(Canvas.Handle, StyleServices.GetElementDetails(tgCellSelected), LRect, ARect);
In Delphi XE2 (and XE3) with the introduction of the vcl styles you must use the same of the above but checking if the current style is a "custom style" (vcl style)
1.for gdsGradient use the GradientFillCanvas method calculating the colors of the gradient on this way
StyleServices.GetElementColor(StyleServices.GetElementDetails(tgGradientCellRowSelectedRight), ecGradientColor1, StartColor); //StartColor is a TColor variable
StyleServices.GetElementColor(StyleServices.GetElementDetails(tgGradientCellRowSelectedRight), ecGradientColor2, EndColor);//EndColor is a TColor variable
2.for gdsClassic
StyleServices.GetElementColor(StyleServices.GetElementDetails(tgClassicCellRowSelectedRight), ecFillColor, LColor); //LColor is a TColor variable
If you want check a sample of how the VCL draw a selected (highlighted) cell/row try the implementation of the TCustomGrid.DrawCellHighlight method.

Resources