Knowledge Base Alert February, 2015


VCL

FIREMONKEY

Unit scope names:

Making sure you have the right unit scope names setup in your projects or sample projects



If you get an error that a standard Delphi unit in the uses list of your project or our sample projects are not found, for example: An error message '[dcc32 Fatal Error]: F1026 File not found: "C:\Program Files(x86)\tmssoftware ... Registry.dcu' appears when compiling a TMS Demo project, this most likely indicates the unit scope names are not setup correct in the project. When a project file contains no unit scope names, the IDE initializes the unit scope names of the project to the default unit scope name list. Sometimes, this default list is incorrect and some unit scopes are missing. In this case, add the appropriate unit scope name:
  • Open the project in Delphi
  • Right-click the project in the Project Manager
  • Select “Options”
  • Select “Delphi Compiler” in the left-side pane of the dialog that appears
  • Add “System.Win;” to the Unit scope names




THTMLCheckList:

How to make the THTMLCheckList only let one check box marked at a time



You can easily have a radiobutton-like behavior in THTMLCheckList by adding the following event handler for OnCheckClick:

procedure TForm5.HTMLCheckList1CheckClick(Sender: TObject; Index: Integer); 
begin
  HTMLCheckList1.UnCheckAll;
  HTMLCheckList1.Checked[Index] := true; 
end;
	




TAdvStringGrid:

How to handle the event of changing the combobox from the TColumnComboEditLink component in a TAdvStringGrid



Following code with a TAdvStringGrid and a TColumnComboEditLink on the form demonstrates how you can handle the ComboChange event:

procedure TForm1.AdvStringGrid1GetEditorProp(Sender: TObject; ACol,
  ARow: Integer; AEditLink: TEditLink);
begin
  ColumnComboEditLink1.Combo.OnChange := ComboChange;
end;

procedure TForm1.AdvStringGrid1GetEditorType(Sender: TObject; ACol,
  ARow: Integer; var AEditor: TEditorType);
begin
  AEditor := edCustom;
  AdvStringGrid1.EditLink :=ColumnComboEditLink1;
end;

procedure TForm1.ComboChange(Sender: TObject);
var
  cc: TColumnComboBox;
begin
  cc := Sender as TColumnComboBox;
  advstringgrid1.Cells[0,0] := inttostr(cc.ItemIndex) + ':'+ cc.ComboItems.Items[cc.ItemIndex].Strings[0];
end;
	




TAdvStringGrid:

How to initialize the TAdvGridHeaderList with hidden columns



To allow an easy customization of what columns to show in a grid by the user, an often used user interface is a list holding the available columns and allowing the user to drag & drop from the grid the columns that should be hidden or drag columns that should be displayed from the list to the grid. To achieve this functionality, a component is offered that integrate much of this functionality: TAdvGridHeaderList. The TAdvGridHeaderList is a listbox-style control that holds indexes of available (hidden) columns. By means of drag & drop from the column header to the list and vice versa, it is possible to define what columns to show or not show in the grid.

Here you can download a demo that shows how you can initialize a TAdvGridHeaderList with hidden columns





TAdvStringGrid:

How to programmatically set focus to the search box in the grid search footer



You can do this with:

grid.SearchPanel.EditControl.SetFocus;
	


TADVGridExcelIO:

How to set the Decimalseparator when exporting a grid to Excel with GridExcelIO.XLSExport



For numbers, what you see in Excel depends on what you have configured in Excel. The numbers are by default exported as doubles, not strings, so there is no “,” or “.”.

By default Excel uses whatever your machine settings are to display the file: So if the machine in China has Excel configured to use “.” as decimal separator, it should show as “.”

You can also override the setting from Excel itself. For example, in my Spanish Excel I see “,” as decimal separator:


But if I go to File->Options->Advanced and change the setting:


Now Excel will show the same file as:


This setting (show a . or a ,) is not stored in the file anywhere, this is a setting of Excel itself.

So, if you are exporting as numbers (which is the best idea), then you should see whatever the user has configured in his machine.

I would recommend that you export numbers as numbers, not strings. This will ensure the numbers show in the user locale. To do this, just comment the line “ExportCellFormats := false”.

This code:

begin
  aGrid.Floats[1, 1] := 3.4;
  GridExcelIO.GridStartCol:= 0;
  GridExcelIO.GridStartRow:= 0;

  with GridExcelIO.Options do begin
     //ExportCellFormats:= false;
     ExportCellProperties:= false;
     ExportCellSizes:= true;
     ExportWordWrapped:= true;
     ExportOverwrite:= omAlways;
  end;

  GridExcelIO.AdvStringGrid:= aGrid;

GridExcelIO.XLSExport('r:\Test.XLS', 'Test');
end;
	
Should work fine in all locales. Note also that AdvStringGrid has an option:

  aGrid.FormatType := ftExcel;
	
If you set it this way, then instead of formatting the numbers in the grid with Delphi format strings (like “%f”) you can use Excel strings (like “0.000”) and the grid will show them fine. And they will look the same when you export to xls. If changing the format type is not an option, you can always use the event “OnCellFormat” in AdvExcelIO to format the numbers as you want. But using ftExcel and formatting both the grid and the excel file the same is the most elegant solution. No, this is all if you can export as numbers (ExportCellFormats := true). if for any reason you need to export as strings, then you indeed need to change the DecimalSeparator variable. But you need to change it *before* setting the values in AdvStringGrid. This code:

begin
  DecimalSeparator := '.';
    aGrid.Floats[1, 1] := 3.4;
  aGrid.FormatType := ftExcel;
  GridExcelIO.GridStartCol:= 0;
  GridExcelIO.GridStartRow:= 0;


  with GridExcelIO.Options do begin
     ExportCellFormats:= false;
     ExportCellProperties:= false;
     ExportCellSizes:= true;
     ExportWordWrapped:= true;
     ExportOverwrite:= omAlways;
  end;

  GridExcelIO.AdvStringGrid:= aGrid;

GridExcelIO.XLSExport('r:\Test.XLS', 'Test');
end;
	
will work. But this one won’t:

begin
    aGrid.Floats[1, 1] := 3.4;
  DecimalSeparator := '.’;
  aGrid.FormatType := ftExcel;
  GridExcelIO.GridStartCol:= 0;
  GridExcelIO.GridStartRow:= 0;


  with GridExcelIO.Options do begin
     ExportCellFormats:= false;
     ExportCellProperties:= false;
     ExportCellSizes:= true;
     ExportWordWrapped:= true;
     ExportOverwrite:= omAlways;
  end;

  GridExcelIO.AdvStringGrid:= aGrid;

GridExcelIO.XLSExport('r:\Test.XLS', 'Test');
end;
	
This is because then you enter 3.4 in the grid, it will be converted to the string “3,4” (because DecimalSeparator is “,”, it hasn’t changed yet). So later when exporting, this string “3,4” won’t be converted to a number, because now the decimalseparator is “.”.

In general, you should change the decimalseparator at the start of the app or somewhere like that. But as said, if you export as numbers instead of as strings, there shouldn’t be any issues.

TWebUpdate:

How to update files inside a subfolder under the application folder



If you deployed under C:\Program Files (x86)\ there is no other choice than deploying this as application components (i.e. files should be in CAB and CAB should be listed under appcomps=... in the WebUpdate .INF control file) as typically, your installed app isn’t running with admin permissions to be able to write under the protected \Program Files folder.


TTMSFMXNativeLocalAuthentication:

How to verify if TouchID is available on the device



As soon as you add the LocalAuthentication component, you are bound to iOS 8.0. The component already internally checks if authentication is possible before executing it. There is currently no separate verification but if you want to verify if TouchID is available you can use the following code (it requires the FMX.TMSNativeUICore unit)
function TForm1.TouchIDAvailable: Boolean;
var
  ctx: LAContext;
  error: PPointer;
  auth: NativeInt;
begin
  result := False;
  ctx := TLAContext.Wrap(TLAContext.Wrap(TLAContext.OCClass.alloc).init);
  error := nil;
  auth := LAPolicyDeviceOwnerAuthenticationWithBiometrics;
  if ctx.canEvaluatePolicy(auth, error) then
    Result := True;
  ctx.release;
end;




TTMSFMXCloudFaceBook:

When connecting to FaceBook, I get an error similar to: "The URL entered is not permitted by the application configuration."



Please make sure the “Embedded browser OAuth login” is enabled in your app:
  • Go to: https://developers.facebook.com/apps
  • Select your app from the Apps dropdown.
  • Click on the “Settings” section
  • Click on the “Advanced” tab
  • Make sure the “Embedded browser OAuth login” switch is set to “YES”
  • Save changes

TMS Charts for FireMonkey:

How to add animation when series are added



The TMS Chart for FireMonkey includes a simple animation mode to animate the series from 0 values to the values that are added or vice versa. The AnimationFactor and AnimationFlow properties on Series level determine the speed and mode. There are 2 events that can be used to trace progress: OnAnimateSerieStarted and OnAnimateSerieFinished.

Here you can download a demo that adds animation and triggers it from a button click. Clicking a second time reverts the bars back to zero.



As always, we thank all users for the numerous inputs, feedback, comments and suggestions. This is an invaluable help to steer our developments here at TMS software. We continue to look forward to all your further communications to direct our team to provide you better tools and components for your needs.

Kind regards,
TMS software team
Email: info@tmssoftware.com
Web: http://www.tmssoftware.com
Support, FAQ & Manuals: http://www.tmssoftware.com/site/support.asp


Follow latest developments at tmssoftware.com


NOTICE: If you wish to unsubscribe from the TMS software Newsletter, please click here.