Pascal ObjectListView - lazarus

I have been working with a wxpython control called objectlistview which makes it very easy to list objects directly in the listview. Is there a control similar to objectlistview in object pascal (lazarus in my case)?
I know how to attach an object to list, but its not the same, since the list/grid controls don't work directly with the objects.

In a form just drop a TTIPropertyGrid from the package RTTI controls.
Then in the code you can assign what the grid has to display, for example the current form itself:
procedure TForm1.FormCreate(Sender: TObject);
begin
TIPropertyGrid1.TIObject := self;
end;

Related

Assign the same event for multiple components on windows forms designer

My program's GUI has a table with a textbox in each cell. When the user types something on a cell I want my program to get that something, plus the row and column the cell occupies on the table.
Creating an event for each cell manually is a lot of work, and each event would do the same thing, so I was wondering if there's an easier way to do this?
You can use one event handler function for several events, in your case the problem is to determine who has raised the event.
It is important to mention that tablelayout panels don't actually have cells, where you could think of container of objects. Some tricks have mentioned here for how to detect clicked row and column of changed textboxes(this link provided example of buttons but it is the same for texboxes too) but I highly recommend to use GridViews instead.

Delphi fmx move borderless form

How to make a form move in Delphi FMX also when you move the mouse fast. ?.
I have tried the code below but when you move the mouse to fast it stop's to work.
How to drag a borderless FMX form on the screen through another object?
Though it's mentioned in the post linked as a comment of OP I think it won't hurt to add it here too, as it's not the accepted answer over there some people searching for this at a later date may miss it. Also make sure it actually is the left mouse button, unless you want to have it drag with other buttons too.
procedure TMyForm.DragPanelMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Single);
begin
if (Button = TMouseButton.mbLeft) then StartWindowDrag;
end;

Resizing a Image to selection rectangle Delphi

Hi i cant figure out why this wont work.
I have a image and a selection and i want the image to always be the same size and position as the selection so i put this code in a timer:
procedure TfrmMainUI.tmrUpdateTimer(Sender: TObject);
var i : integer;
begin
Image1.Width:=Selection1.Width;
Image1.Height:=Selection1.Height;
Image1.Position.X:=Selection1.Position.X;
Image1.Position.Y:=Selection1.Position.Y;
end;
But it doesn't work.
What is supposed to happen is the image resizes to the selection and its position also follows the selection.
But what happens is that i can move and resize the selection and the image just stays where it is and doesn't resize.
As #Mike Sutton pointed out in the comments, you should be using the OnTrack event of TSelection to trigger updates to your image.
The documentation says:
The event handler of the OnTrack event is called cyclically from the
MouseMove method while the TSelection object is in the process of
moving or resizing.
Write a custom OnTrack event handler to perform a specific action when
TSelection is in the process of moving or resizing.
You state in a comment, the components are created dynamically at runtime, rather than on the designtime surface. So you will also need to assign your handler in code. Do it like this:
Selection1.OnTrack := SelectionTrack;
Your event handler will look like this:
procedure TfrmMainUI.SelectionTrack(Sender: TObject);
begin
Image1.Width:=Selection1.Width;
Image1.Height:=Selection1.Height;
Image1.Position.X:=Selection1.Position.X;
Image1.Position.Y:=Selection1.Position.Y;
end;
You also say in the comments that you need to track selection changes for a number of linked images and selections. You can modify the event handler like this:
procedure TfrmMainUI.SelectionTrack(Sender: TObject);
var
Selection: TSelection;
Image: TImage;
begin
Selection := Sender as TSelection;
Image := ImageFromSelection(Selection);//you need to implement this function
Image.Width:=Selection.Width;
Image.Height:=Selection.Height;
Image.Position.X:=Selection.Position.X;
Image.Position.Y:=Selection.Position.Y;
end;

How to create a window in smalltalk

I am trying to make a window show up, but i keep getting a message not understood error.
The snippet:
Window new
label: 'Hello';
open
You can use this:
ScheduledWindow new
label: 'Hello';
open
Or to open larger:
ScheduledWindow new
label: 'Hello';
openIn: (20#20 extent: 300#300)
I suspect, however, that this isn't what you really want to do since it's hard to work with a window that's built this way. Can you explain more about what you want to do?
Ok, for a game like that you want to use a custom control. You start by creating a subclass of View for your game and override the displayOn: method to display the view. You can add the view to the UIPainter canvas using a ViewHolder. Set the View: property to be the name of a method that returns your custom view.
To intercept mouse clicks, you'll need to have a custom controller for your view. You'll subclass Controller or one of its subclasses to create the Controller. A method called defaultControllerClass in the View returns the name of the controller class. In the controller, you can intercept mouse events.
I suggest that you load an example game to get you started. Open the Parcel Manager, and select Toys from the list. You should see SpiderSolitaire there. This is a game written for VisualWorks that displays a custom view, does some simple animation on that view, and intercepts mouse events. That should serve as a good example to use.

NSTableView and NSOutlineView drag-and-drop

I have an NSTableView and an NSOutlineView, both with their content provided by bindings, that I'd like to have some drag-and-drop functionality:
Drag rows from Table A onto a row of Outline B, where they will be copied into a data structure which the row in Outline B represents.
Drag a row from Outline B onto another row in Outline B, which will copy the data represented by the first row into the data represented in the second row.
I've read Apple's drag-and-drop documentation and gotten just about nowhere. It doesn't really seem to apply to what I need to do. What am I missing?
The page you linked to is pretty clear about what you need to do. In table A's data source, implement registerForDraggedTypes: and tableView:writeRowsWithIndexes:toPasteboard: to put some private TableAPasteboardType data on the pasteboard.
In outline B's data source, implement the same two methods and put some private OutlineBPasteboardType data on the pasteboard.
Finally, implement tableView:validateDrop:proposedRow:proposedDropOperation: and tableView:acceptDrop:row:dropOperation: to check the pasteboard for either TableAPasteboardType or OutlineBPasteboardType and make the appropriate changes to your bound model, depending.
It's pretty straightforward once you just plow in and do it.
You need a data source—AFAIK, you can't make this happen with Bindings alone.
The unfinished Adium Xtras Creator, which is under the BSD license, includes an array controller that you can set as the data source to get drag-and-drop in a Bindings-powered table view.
This requirement may not apply to NSOutlineView and NSTreeController. I haven't tried that.
In MacOS 10.7 some new protocols were added to implement this.
There is a lack of documentation for tables at the moment but you can find some nice examples:
DragNDropOutlineView
SourceView
TableViewPlayground
For NSTableViwew the Protocol NSTableViewDataSource defines the following methods:
(BOOL)tableView:writeRowsWithIndexes:toPasteboard:
tableView:validateDrop:proposedRow:proposedDropOperation:
tableView:acceptDrop:row:dropOperation:
For NSOutlineView the Protocol NSOutlineViewDataSource defines the following methods:
(BOOL)outlineView:writeItems:toPasteboard:
(NSDragOperation)outlineView:validateDrop:proposedItem:proposedChildIndex:
(BOOL)outlineView:acceptDrop:item:childIndex:
These are the minimum requirements to implement for each view type.
The use cases are quite similar.
If the toPasteboard: method returns YES, the drag is started.
The validateDrop: method controls which target node is allowed by updating the marker in the view
Return YES for the acceptDrop: method if the drop was successful
This lead to two sub-usecases you have to manage. The first one is a drag & drop within the same view or the same operation between two views. Additionally you may distinguish between move, copy or delete operations. A nice example is how the breakpoints work with drag & drop in Xcode.
The tableView has some additional methods to customize drag & drop, but the ones I mentioned are the key methods to get it working.

Resources