Tips and Frequently Asked Questions
TAdvSmoothDock and MDI forms
TAdvSmoothDock is designed to be used on non-MDI applications. The TAdvSmoothDock is not compatible with MDI forms.
The TAdvSmoothDock hooks on the main form so it can be moved, activated, deactivated according to the main form events.
MDI child windows / frames and forms called from the main form are not supported.
Update smooth controls faster with BeginUpdate and EndUpdate
This short article describes the use of BeginUpdate and EndUpdate methods to allow faster updating and repainting.
When creating a smooth listbox or a smooth imagelistbox with 500+ items in code, it tends to be slow when starting the application.
For each item that is added / deleted or updated, the listbox is updated. It is just a matter of milliseconds to update the listbox for one item, but imagine the time that is needed to update 500 items. And these items are drawn with the default layout. With more advanced items the update process can be painfully slow.
Because we cannot predict when the user wants to update the listbox, we have implemented a BeginUpdate and EndUpdate which *blocks* the painting of the listbox until the EndUpdate is called. Then all the calculations and painting is executed once, with all the new information the user has inserted in the items.
Below is a code sample based on the TAdvSmoothListBox component to update all items between a BeginUpdate and EndUpdate.
var
i: integer;
begin
AdvSmoothListBox1.Items.BeginUpdate;
for I := 0 to AdvSmoothListBox1.Items.Count - 1 do
begin
AdvSmoothListBox1.Items[i].Caption := 'Item Updated !';
end;
AdvSmoothListBox1.Items.EndUpdate;
Important note !: All BeginUpdate calls must end with an EndUpdate. In other words: The count of BeginUpdate and EndUpdate calls must be equal. When this condition is false, the listbox will not update, and the listbox will not respond to other update calls.
A List of components which currently implement the BeginUpdate and EndUpdate:
- AdvSmoothListBox (AdvSmoothListBox.Items.BeginUpdate / EndUpdate)
- AdvSmoothImageListBox (AdvSmoothImageListBox.Items.BeginUpdate / EndUpdate)
- AdvSmoothDock (AdvSmoothDock.BeginUpdate / EndUpdate)
- AdvSmoothExpanderGroup (AdvSmoothExpanderGroup.BeginUpdate / EndUpdate)
- AdvSmoothSplashScreen (AdvSmoothSplashScreen.BeginUpdate / EndUpdate)
- AdvSmoothTimeLine (AdvSmoothTimeLine.BeginUpdate / EndUpdate)
- AdvSmoothTouchKeyBoard (AdvSmoothTouchKeyBoard.Completion.BeginUpdate / EndUpdate)
Controlling how long the item jumping lasts.
When an item is clicked or double clicked an extra visual feature can be started to indicate the item has been clicked: Set Jump to true to allow the item to jump. Set Jump to false to stop the jumping. This way it is under full control of the application code how long the item jumping lasts.
With this code a Timer is started to count 3 seconds before the item stops jumping:
var
time, clickeditem: integer;
implementation
{$R *.dfm}
procedure TForm1.AdvSmoothDock1ItemClick(Sender: TObject; ItemIndex: Integer);
begin
Timer1.Enabled := true;
time := 0;
clickeditem := ItemIndex;
AdvSmoothDock1.Items[clickeditem].Jump := true;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
var
i: integer;
begin
if time >= 3 then
begin
Timer1.Enabled := false;
for I := 0 to AdvSmoothDock1.Items.Count - 1 do
AdvSmoothDock1.Items[I].Jump := false;
end;
Inc(time);
end;
How to programmatically load an image from an imagelist
You can load the images with the code below:
For .BMP files
var
I: Integer;
bmp: TBitmap;
begin
bmp := TBitmap.Create;
for I := 0 to ImageList1.Count - 1 do
begin
ImageList1.GetBitmap(I, bmp);
AdvSmoothDock1.Items.Add.Image.Assign(bmp);
end;
bmp.Free;
For .ICO files
var
I: Integer;
ico: TIcon;
ms: TMemoryStream;
begin
ico := TIcon.Create;
for I := 0 to ImageList1.Count - 1 do
begin
ImageList1.GetIcon(I, ico);
ms := TMemoryStream.Create;
ico.SaveToStream(ms);
AdvSmoothDock1.Items.Add.Image.LoadFromStream(ms);
ms.Free;
end;
ico.Free;
TAdvSmoothDock on the desktop
AdvSmoothDock on the desktop
The TAdvSmoothDock can also be placed on the desktop with some minor code changes. Download and examine the sample below:
Download the demo
Below is a preview if the demo is running:
Disable internal drag/drop in TAdvSmoothDock
To disable the internal item drag/drop in the TAdvSmoothDock add the
OnItemStartDrag event and set Allow to false:
procedure TForm1.AdvSmoothDock1ItemStartDrag(Sender: TObject;
DragItem: TAdvSmoothDockItem; var Allow: Boolean);
begin
Allow := false;
end;