Tips and Frequently Asked Questions
Drag and Drop over TCustomItem
Drag & Drop needs to be implemented manually, below is code that inserts or adds an item based on TCustomItem. The item also be a custom class that inherits from TCustomItem.
The code below is drag & drop code based on 2 TAdvPolyList instances, where the item to be dropped is obtained from the DropItem function. But the Source can come from another component as well.
procedure TForm1.AdvPolyList1DragDrop(Sender, Source: TObject; X, Y: Integer);
var
it, itdrop: TCustomItem;
begin
it := (Source as TAdvPolyList).DropItem;
itdrop := AdvPolyList1.List.ItemAtXY(X, Y);
if Assigned(itdrop) then
AdvPolyList1.InsertItem(itdrop.Index, TCustomItemClass(it.ClassType)).Assign(it)
else
AdvPolyList1.AddItem(TCustomItemClass(it.ClassType)).Assign(it);
end;
procedure TForm1.AdvPolyList1DragOver(Sender, Source: TObject; X, Y: Integer;
State: TDragState; var Accept: Boolean);
begin
Accept := Source is TAdvPolyList;
end;
Add items in C++
To item of a specific class type to the TAdvPolyList, the equivalent C++ code for the following Delphi code is:
var
item: THTMLItem;
begin
item := THTMLItem(AdvVerticalPolyList1.AddItem(THTMLItem));
end;
{
THTMLItem *item;
item = (THTMLItem*)AdvVerticalPolyList1->AddItem(__classid(THTMLItem));
}
Resizing AdvPolyPager items at runtime
To resize items at runtime:
AdvPolyPager1.ListAutoSizeMode := asmcontrol;
for I := 0 to AdvPolyPager1.List.Items.Count - 1 do
AdvPolyPager1.Items[i].Width := 400;
Update the poly list 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 poly list with 500+ items in code, it tends to be slow when starting the application.
For each item that is added / deleted or updated, the list is updated. It is just a matter of milliseconds to update the list 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 list, 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 theTAdvPolyList component to update all items between a BeginUpdate and EndUpdate.
var
i: integer;
begin
AdvPolyList1.BeginUpdate;
for I := 0 to AdvPolyList1.ItemCount - 1 do
begin
AdvPolyList1.Items[i].Height := 50;
end;
AdvPolyList1.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 list will not respond to other update calls.
Reordering items
Reordering items is as simple as setting a new index property on the item:
AdvPolyList1.Items[0].Index := 1;
The item will automatically be moved to the new position in the collection. Typecasting is not necessary for properties that are common and available on the base class.
This is also explained at page 12 of the
PDF Developers Guide
Accessing items
Items can be accessed with the “Items” property of the poly list and must be typecasted to the correct class type:
TTextItem(AdvPolyList1.Items[0])
This is also explained at page 12 of the
PDF Developers Guide
Adding / removing items
The poly list has a polymorph collection of TCustomItem classes. Each descending class inherits all properties and can also be added to the collection. To access the properties specifically for a descending item, the item must be added to the list and typecasted to the correct class to gain access to the properties.
Adding an item:
with TTextItem(AdvPolyList1.AddItem(TTextItem)) do
begin
Caption := 'This is a sample';
end;
Inserting an item at a specific position in the collection:
with TTextItem(AdvPolyList1.InsertItem(0, TTextItem)) do
begin
Caption := 'This is a sample';
end;
Removing an item at a specific position:
AdvPolyList1.RemoveItem(0);
To compile the project, the unit must manually be added to the uses list. In this case the unit is GDIPTextItem which contains the TTextItem class.
The rule for adding the correct unit is:
(T)CustomItem -> (GDIP)CustomItem
Class -> Unit
When you are not sure what unit you must add to compile the project, you can always add the item of choice at designtime, so the unit is automatically added to the uses list.
This is also explained at page 12 of the
PDF Developers Guide
Adding pictures to the TGDIPPictureContainer at runtime
Below is a code snippet that shows how an image is loaded from file and added to the TGDIPPictureContainer:
with GDIPPictureContainer.Items.Add do
begin
Picture.LoadFromFile('myimage.png’);
Name := 'NEW';
end;
To remove a picture from the TGDIPPictureContainer later:
with GDIPPictureContainer.Items.Items[0].Free;
This is also explained at page 68 of the
PDF Developers Guide.
Using the fill editor at runtime
It is easy to use the fill editor at runtime. To do this, add the unit AdvSmoothFillEditor to the uses list and add following code:
var
filldlg :TAdvSmoothFillEditorDialog;
begin
filldlg := TAdvSmoothFillEditorDialog.Create(self);
filldlg.Fill := AdvPolyList1.Fill;
filldlg.Execute;
end;
With this code snippet, the TAdvPolyList fill can be edited at runtime.
This is also explained at page 67 of the
PDF Developers Guide
Drag & drop items
Drag & drop from one list to a second list can be done by implementing 2 events. Allowing an item to be dropped is setting the Accept parameter true. Dropping the item can be done by calling AddDropItem and as parameter the SelectedDragDropItem from the first list.
procedure TForm1.AdvPolyList2DragOver(Sender, Source: TObject; X, Y:
Integer; State: TDragState; var Accept: Boolean);
begin
Accept := Source is TAdvPolyList;
end;
procedure TForm1.AdvPolyList2DragDrop(Sender, Source: TObject; X, Y: Integer);
begin
AdvPolyList2.AddDropItem((Source as TAdvPolyList).SelectedDragDropItem);
end;
Also internal drag drop is supported. This can be switched off by setting the Reorder parameter to false. When Reorder is true, a default red line will appear that will follow the mouse and show the insert position of the item you want to move.
This is also explained at page 34 of the
PDF Developers Guide
Is any Microsoft licensing required to use the TMS Poly list controls similar to the Office 2007 ribbon ?
TMS Poly list controls can be used for so much more than just the
Office 2010 application menu. They extend these controls and are in
several ways more versatile. Ribbon UI licensing does not apply on
such separate controls.