Jump to content

Incus J

Members
  • Content Count

    80
  • Joined

  • Last visited

Community Reputation

2 Neutral

Technical Information

  • Delphi-Version
    Delphi 10.4 Sydney

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

  1. I've just tried your suggestion, and it works perfectly. I don't think I would ever have thought to look under .Model for a SelectText method. It even scrolls the line into view, and it works when the memo is ReadOnly too. Thank you Lajos!
  2. Incus J

    Calculate the width of a Popup Menu?

    I'd like to calculate the width of a Popup Menu before it is displayed, so that I can position and align it accurately when I call its .Popup(x,y) method. function CalcPopupMenuWidth(popup : TPopupMenu) : single; var i : integer; w : single; item : TMenuItem; begin result := 0; for i := 0 to popup.ItemsCount-1 do begin item := popup.Items[i]; w := popup.Items[i].Width; if w > result then result := w; end; end; The above approach iterates over the individual menu items, to determine the widest item. It almost works, in that it calculates the width correctly, but only after the Popup Menu has been displayed once. If the Popup Menu has never been displayed (yet) then this code always returns a value of 50. I'm guessing maybe that's a default width for a TMenuItem, which gets updated with the actual width shortly before it is displayed. How can I calculate the dimensions of a Popup Menu before displaying it?
  3. Incus J

    TButton : How to display the assigned Popup Menu?

    I'll go with the above code for now, until I find a better way to do it. I'm just trying to figure out how to calculate the width of the Popup Menu before it appears, so I can align it centrally or right-aligned. At the moment it displays left aligned (to the left edge of the button) - right aligned to the right edge of the button would be particularly useful as the button is positioned at the very right hand side of the form. I could do with a property like : PopupMenu.Width; //no such property TMenuItem has CalcSize and CalcRenderSize so perhaps I could iterate over the Items to determine a value for the widest Menu Item.
  4. Incus J

    TButton : How to display the assigned Popup Menu?

    TButton.DropDownMenu looks to be the right thing to use for a VCL application. The FMX TButton doesn't have that property though, so perhaps FMX lacks this capability.
  5. Incus J

    TButton : How to display the assigned Popup Menu?

    Yes, I'm probably trying to use it for something other than intended (this happens to me quite a lot). Still, click a button for a menu to appear, must be a fairly common requirement. I'll see whether FMX offers another control better suited for this. Ah - I've just seen your last reply, thank you - I will take a look.
  6. Incus J

    TButton : How to display the assigned Popup Menu?

    Hi Virgo - Yes, it pops up OK on right click (but the menu tends to overlap the button, obscuring it). I've come up with this for left click : procedure TmyForm.myButtonClick(Sender: TObject); var h:single; pt:TPointF; begin h:=myButton.Height; pt:=myButton.LocalToAbsolute(PointF(0,h)); pt:=Self.ClientToScreen(pt); myButton.PopupMenu.Popup(pt.x,pt.y); end; ...though it seems a bit convoluted, and I'm not sure how robust it is.
  7. I've created a TPopupMenu, and assigned it to the PopupMenu property of a TButton. When the button is left clicked I'd like the assigned PopupMenu to appear just below the button. The documentation suggests : "Use PopupMenu to set the context menu of the current control. The pop-up window is displayed when ShowContextMenu is called." In the button OnClick handler, I've added : procedure TmyForm.myButtonClick(Sender: TObject); begin myButton.ShowContextMenu; end; This doesn't compile : [dccosx64 Error] myForm.pas(73): E2362 Cannot access protected symbol TControl.ShowContextMenu The procedure ShowContextMenu seems to be Protected. Perhaps it is not meant to be called directly, but I haven't spotted an auto-popup option yet. ShowContextMenu takes coordinates, but I'd like FMX to decide the best place to display the PopupMenu for me, rather than me having to specify coordinates, because the form can be resized or maximised, and the width of the PopupMenu may vary depending on the length of the menu items, so the ideal position is likely to be variable. How do I get a button to show its assigned popup menu (in a sensible position) when left clicked?
  8. Thanks Uwe, I've had a look in the Object Inspector, and in the documentation, but there doesn't seem to be a HideSelection property on TMemo. However there is HideSelectionOnExit. I have that set that to false at the moment, but no joy - when I make a selection in code via SelStart and SelLength, no highlight is displayed.
  9. I'd like to search for, and then highlight a line or phrase of text in a TMemo. I can get the Caret to move to the start of the correct location via SelStart, but when I set SelLength the selection does not expand visibly. The text highlight does not appear. Here's my approach : s := 'section'; i := MyMemo.Lines.Text.IndexOf('['+s+']'); if i>-1 then begin MyMemo.SetFocus; MyMemo.SelStart := i+1; MyMemo.SelLength := s.Length; MyMemo.Repaint; //MyMemo.ScrollTo(MyMemo.Caret.Pos.Y,0); I suspect the selection is actually being made successfully, internally behind the scenes, but the control is failing to highlight its current selection. If I start typing, the not-visibly-selected text is replaced with what I type. I added Repaint to see whether that would give the control a gentle kick to persuade it to display its selection highlight, but no joy so far. I can highlight text with the mouse OK, and the control is set to display its highlight whether focussed or not (HideSelectionOnExit is false). The memo is not currently ReadOnly. I've also tried toggling the control type between Platform and Styled, but the behaviour remains the same. (You can also spot that I'd eventually like to scroll the selected line into view, and I'd also like this to happen on a ReadOnly memo without giving the memo focus - but one step at a time.)
  10. Thanks Dalija - I've added my vote.
  11. That's unfortunate, I did like the concept of helpers. Really I just wanted to add a couple of extras, to make my coding a little less verbose with fewer brackets e.g. mystring := mystring.Trim.Capitalise; vs mystring := TMyStringUtils.Capitalise(Trim(mystring)); ...the flow and readability of the first version has some appeal. I find it easier and quicker to parse. I think adding the ability to inherit from an existing helper would make helpers more practical. Better would be types supporting multiple helpers simultaneously. Hey, I can dream 🙂 Thank you for the heads up!
  12. I’m creating a record helper for string. It seemed like a good idea at first, until I realised string already has a helper, and I can’t inherit from it (?) So I think I need to duplicate those existing default string helper functions in my new string helper, and call into the original. Something like this : function TStringHelper.ToInteger: integer; begin result := System.SysUtils.TStringHelper.ToInteger(Self); end; [dccosx64 Error] My.Str.Helper.pas(36): E2018 Record, object or class type required Don’t laugh, am I anywhere close…?
  13. I have a two column TStringGrid on my main form. I set the column widths in the form designer at design time. I think this used to work, but at runtime most designer column widths are now ignored - all columns default to the width of the first column. Is it possible to get the app to apply the other column widths set at design time? I can set a column width in code : MyGrid.Columns[1].Width:=200; but that involves a bit of trial and error, so I'd prefer to set it visually. Incidentally while playing around with this, I found : MyGrid.Columns[1].Align:=TAlignLayout.Client; autosizes the last column to fill remaining space, which is useful. However this TStringColumn Align property does not appear in the Object Inspector - it is not a Published property, so this can only be set in code.
  14. Incus J

    TListView OnChange Event Doesn't Fire

    Oh, I never thought of that. At the moment the following seems to work but requires two event handlers : procedure TMainForm.MyListViewChange(Sender: TObject); begin MyController.ShowMatch(MyListView.ItemIndex); //Pass the new index to my code for processing. end; procedure TMainForm.MyListViewItemClick(const Sender: TObject; const AItem: TListViewItem); begin MyListView.ItemIndex:=AItem.Index; //Set the item index manually. MyListView.OnChange(Sender); //Call the OnChange handler. end; So OnChange is the same as before (fired for arrow keys, and also click-and-hold) OnItemClick fires for a normal mouse click, sets the ItemIndex itself, then simulates an OnChange call. That combination seems to catch all the various ways an item can be selected. However it's likely OnChange will get called multiple times per selection in some cases (i.e. when Click and Change both fire). There's also a workaround posted in the bug report comments, which looks to achieve the same kind of thing in reverse.
  15. Incus J

    TListView OnChange Event Doesn't Fire

    OK, I've voted! (and added a comment) Now I have to figure out a workaround. OnClick seems to fire, but unfortunately it fires before the new selection comes into effect. So ItemIndex still points to the previous item. I wonder if there is a way to retrieve the new upcoming index value from within the OnClick event handler? Or by the time OnMouseUp fires, ItemIndex might have updated by then? Or maybe in OnClick I could call Application.ProcessMessages followed by a call to the OnChange event handler manually. Could get messy.
×