TListbox.topIndex is not apparent in Delphi xe5. How do I perform a similar function ? I would like to have the listbox scroll so that the selected item is at the top of the listbox.
I have found other examples where I can set ListBox.itemIndex, but that doesn't scroll so that the selected item is at the top of the listbox.
Thank you in advance.
I have used this code which works:
var
THackListBox = type TListBox;
begin
THackListBox(ListBox1).VScrollBar.Value := 0;
The VScrollBar property is protected but this method exposes the property and allows the value to be set to zero.
On Windows, the VCL TListBox has a public TopIndex property, which internally uses the LB_SETTOPINDEX message.
There is no equivalent in the FireMonkey TListBox. The only option I see would be to call the ListBox's ScrollTo() method to manually scroll the ListBox so the target list item appears where you want it to be.
Related
I have a FireMonkey application with multiple buttons on it (actually, rectangles). I want to have one procedure called on any click on the Form, besides the specific action of each button.
Since the HitTest of each child component is set to True, the parent's HitTest is automatically false.
So what is the right way to deal with this?
A silly workaround would be to assign this procedure to each button's OnClick event, but this will not make any sense when I have a Form with hundreds of buttons on it.
I found solution for vcl.
you can find component base of mouse position by this code:
var
ctrl : TWinControl;
begin
ctrl := FindVCLWindow(Mouse.CursorPos);
if ctrl.Name = '' then
ShowMessage(ctrl.Owner.Name);
For FireMonkey no result founded but You can get mouse position on form and analyze component base on result of that point and find name of it then proceed to your event base of that component.
A Simple Interceptor/Interposer Class of TRectangle did the job!
Thanks to everyone for their input.
i am using Delphi XE7 Firemonkey.
I would like to move around TTabItems of a TTabControl component like modern Webbrowsers do with their tabs.
I found some tutorials but those are for VCL (http://www.swissdelphicenter.com/de/showcode.php?id=963)
What i also found is TChromeTabs (http://www.easy-ip.net/tchrometabs.html) but this was also made for VCL only.
Any help is greatly appreciated
You'll first need to set the DragMode on each of your TTabItems to dmAutomatic. From there a TTabItems OnDragDrop procedure is what you will need to write code for. I've provided a quick snippet on how to get your source and destination TTabItems. What you want to achieve when the "drop" is performed is up to you:
OnDragDrop
//This is your TTabItem that is being dragged
TTabItem(Data.Source).Index//Index of this object in your TTabControl
//This is your TTabItem that is being "dropped" to
TTabItem(Sender).Index//Index of this object in your TTabControl
Also if you assign this code to the OnDragMove of your TTabItem you will get a blue drag highlight showing what tab this is currently on:
OnDragMove
Operation:=TDragOperation.Move;
Hope this helps
I am developing an application for mobile (android and ios) by Delphi xe5.
I am willing to create this UI:
I tried TListBox but image on left and right cant be set.
I tried TListView but same problem as TListBox
I tried TGrid with custom column, The problem of texts and images is solved but I can't create headers of each rows (it hasn't something like colspan)
What I need is to create a custom control and repeat it.
What is the best solution?
Any solution or guide line will be appreciated.
Solution
Thanks #Mike Sutton for answer, this is the result
The style here is so different from a standard TListBoxItem style that is probably makes sense to start from scratch, in which case the issues with accessing the default styles become immaterial.
Add a TStyleBook to your form.
Set the StyleBook property of the form to point to it.
Double click the icon to open the editor.
Drag a TLayout to the structure panel and drop it on the only item which will be there.
Set the StyleName property of the TLayout (e.g. ScoreListBoxItemStyle).
Drag/drop other components to build up the layout you want (remember TLayouts for 'hidden' positioning).
Set the StyleName property of any components you want reference from your code.
Subclass TLIstBoxItem to TScoreListBoxItem (if using the StyleName suggested above).
Add properties for your text, images etc.
In the setter methods for each of these, cache the data and call a method such as:
procedure SetFlag1;
var O: TFMXObject;
begin
O := FindStyleResource('flag1'); //StyleName of the item
if O is TImage then
TImage(O).Bitmap.Assign(FFlag1);
end;
Override the ApplyStyle method and call all of your methods that set the data in the style.
Now create your items in code:
Item := TScoreListBoxItem.Create(Self);
ListBox1.AddObject(Item);
Item.Flag1.LoadFromReource ...
...
Here's an idea that I don't have time to test:
Create a descendant of a TListBoxItem and in that add you two images as normal TImages. I'm pretty sure that a TListBoxItem can parent an object. You'll have to place the images on the listbox item where you want them. Then whenever you add an item to the listbox item just pass in your own descendant.
(If this doesn't work someone let me know and I'll delete this.)
I have a TListView (actually, a custom descendant) display in ViewStyle vsReport. One row is selected. I would like to get the screen coordinates of that row (or a cell within that row). Is there any way for me to do this?
(My goal is to display a small form over the list view giving the effect that it dropped down from the selected row).
I am using Delphi 2010 for this particular application.
For a list view in vsReport style I believe the best approach is to use the LVM_GETITEMRECT and LVM_GETSUBITEMRECT messages.
The VCL does not wrap this functionality up for you but it should not be too difficult to work it out from the MSDN docs.
Whilst it is very simple to use the TListItem.Position property exposed by the VCL, as far as I can tell this does not help you obtain the row height or indeed the coordinates of sub items.
Update
As NGLN very helpfully points out, the CommCtrl unit does expose ListView_GetItemRect and ListView_GetSubItemRect which are more convenient to use than the equivalent Windows messages above.
var
sel: TListItem;
pnt: TPoint;
begin
sel := ListView1.Selected;
if not Assigned(sel) then Exit;
pnt := ListView1.ClientToScreen(Sel.Position);
I have a TCategoryPanelGroup instance dropped on a form. I would like to allow the user to reorder the categories. In tryed to reorder Panels[] property - which is a TList - but this doesn't seems to work.
Any idea ?
Effect this change by modifying the position of the panels:
CategoryPanel2.Top := 0;
CategoryPanel1.Top := CategoryPanel2.Height;