Knowledge Base Alert April, 2016


VCL

FIREMONKEY

INTRAWEB

TAdvStringGrid:

How to get the number of disjunct selected columns



If disjunct column selection is enabled with grid.MouseActions.DisjunctColSelect = true, the number of disjunct selected columns can be retrieved via:

grid.ColSelectCount: integer;

To get the columns that are selected , you can use:

  for I := 0 to advstringgrid1.ColCount - 1 do
  begin
    if advstringgrid1.ColSelect[i] then
      // ...
  end;



TAdvStringGrid:

Persist column state in an INI file and allow column selection via a column picker



Drop a TAdvStringGrid and TAdvGridColumnPicker on the form and add following code:

procedure TForm4.FormCreate(Sender: TObject);
var
  s: string;
  ini: TINIFile;
begin
  AdvStringGrid1.LinearFill(true);
  AdvStringGrid1.SetColumnOrder;
  AdvStringGrid1.Options := AdvStringGrid1.Options + [goColMoving, goColSizing];
  AdvGridColumnPicker1.Grid := AdvStringGrid1;

  ini := TINIFile.Create('.\gridsettings.ini');
  s := ini.ReadString('GRID','SETTINGS', '');
  ini.Free;

  if s <> '' then
  begin
    AdvStringGrid1.StringToColumnStates(s);
    AdvGridColumnPicker1.Init;
  end;
end;

In the form constructor, we are reloading the persisted settings for column with, position, visibility from the INI file and initializing grid and column picker with these settings.

procedure TForm4.FormClose(Sender:TObject;var Action:TCloseAction);
var
  s: string;
  ini: TINIFile;
begin
  s := AdvStringGrid1.ColumnStatesToString;

  ini := TINIFile.Create('.\gridsettings.ini');
  ini.WriteString('GRID','SETTINGS', s);
  ini.Free;
end;


TAdvDirectoryTreeView:

How to get the full path and filename for a selected node



You can retrieve the real node and cast it to a TAdvDirectoryTreeViewNode to retrieve the FileName:

procedure TForm1.AdvDirectoryTreeView1AfterSelectNode(Sender: TObject;
  ANode: TAdvTreeViewVirtualNode);
var
  tn: TAdvDirectoryTreeViewNode;
  s: string;
begin
  tn := (ANode.Node as TAdvDirectoryTreeViewNode);
  s := tn.FileName;
end;


TAdvEdit:

Using the decimal separator when '.' is pressed on the numerical keypad



Set AdvEdit.ExcelStyleDecimalSeparator = true

TMS Advanced Toolbars & Menus:

How to save the position of the ToolBars



When you have set a value for the location in the registry where you want to persist the location, you can either set AdvDockPanel.Persistence.Enabled = true and the dockpanel with load the settings itself or you can programmatically call

AdvDockPanel.SaveToolBarsPosition

AdvDockPanel.LoadToolBarsPosition

to do this programmatically at the time you want.

TTMSFMXPlanner:

Assigning additional data to a TTMSFMXPlannerItem linked to a database



The TMSFMXPlannerDatabaseAdapter component has an OnFieldsToItem event that can be used to bind additional values to properties that are not bindable through the database adapter item property. The following code should be able to accomplish this:

procedure TForm1.TMSFMXPlannerDatabaseAdapter1FieldsToItem(Sender: TObject; AFields: TFields; AItem: TTMSFMXPlannerItem); 
begin
  AItem.DataString := AFields.FieldByName('DataField').AsString;
end;


TTMSFMXPlanner:

How to select all items in the planner



You need to pass the indexes of the items you wish to select to the SelectItems call.

Example:

procedure TForm1.SelectAllItems;
var
  a: TTMSFMXPlannerItemArray;
  i: integer;
begin
  SetLength(a, TMSFMXPlanner1.Items.Count);
  for i := 0 to TMSFMXPlanner1.Items.Count - 1 do
   a[I] := TMSFMXPlanner1.Items[I].Index;

  TMSFMXPlanner1.SelectItems(a);
end;


TTMSFMXDateTimeEdit:

How to add a 'today' button



You can manually add a button to the TTMSFMXDateTimeEdit with the following code:

procedure TForm1.FormCreate(Sender: TObject);
var
  btn: TButton;
  img: TImage;
begin
  btn := TButton.Create(TMSFMXDateTimeEdit1);
  btn.Parent := TMSFMXDateTimeEdit1;
  btn.Align := TAlignLayout.MostRight;
  btn.Width := 20;
  btn.Text := 'X';
  btn.OnClick := TodayClick;
  img := TImage.Create(btn);
  img.Parent := btn;
  img.Align := TAlignLayout.Client;
  img.HitTest := False;
  img.WrapMode := TImageWrapMode.Center;
  img.Bitmap.LoadFromFile('C:\Users\Pieter\Pictures\Icons\led-icons\calendar_1.png');
end;

procedure TForm1.TodayClick(Sender: TObject);
begin
  TMSFMXDateTimeEdit1.DateTime := Now;
end;


TTMSFMXSlider:

How to replace the On/Off text by images



You can add images, and clear the text in the style designer window, available after right-clicking the component and selecting "Edit Custom Style". Programmatically this can be done with the following code:

procedure TForm1.TMSFMXSlider1ApplyStyleLookup(Sender: TObject); var
  el: TFMXObject;
  img: TImage;
begin
  el := TMSFMXSlider1.GetOnElement;
  if Assigned(el) then
  begin
    (el.FindStyleResource('ontextelement') as TText).Text := '';
    img := TImage.Create(el);
    img.Parent := el;
    img.Align := TAlignLayout.Left;
    img.Margins.Left := 10;
    img.HitTest := False;
    img.Bitmap.LoadFromFile('onimage.png');
    img.Width := img.Bitmap.Width;
    img.Height := img.Bitmap.Height;
  end;

  el := TMSFMXSlider1.GetOffElement;
  if Assigned(el) then
  begin
    (el.FindStyleResource('offtextelement') as TText).Text := '';
    img := TImage.Create(el);
    img.Parent := el;
    img.Align := TAlignLayout.Right;
    img.Margins.Right := 10;
    img.HitTest := False;
    img.Bitmap.LoadFromFile('offimage.png');
    img.Width := img.Bitmap.Width;
    img.Height := img.Bitmap.Height;
  end;
end;


TMS IntraWeb Component Pack Pro

Using image files in IntraWeb projects



Always make sure the image file is accessible by the IntraWeb application. In general this means you can put the image files in a subfolder called “wwwroot” of the folder where the executable of your IntraWeb project is generated. Then you can access the image files using a relative path.

Example:

procedure TIWForm1.TIWAdvWebGrid1GetCellData(Sender: TObject; RowIndex,
  ColumnIndex: Integer; var AValue: string);
begin
  if ColumnIndex = 1 then
    AValue :=  '<img src="filename.png">';
end;




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.