Quantcast
Channel: Embarcadero Community - Embarcadero Community
Viewing all articles
Browse latest Browse all 3212

FMX ListView and ListItemEmbeddedControl

$
0
0

I have an FMX Listview in an application. When adding rows I have also add an object that descends from TListItemEmbeddecControl. In the container of the object I create a TEdit control

It all works great. I can see the edit box. It's place in the correct location, height and all. It accepts text input programmatically. How the TEdit does not respond to Keyboard input. When the mouse is placed over the component, the cursor converts to a caret. The TEdit responds to mouse clicks. Just not to keyboard input. 

I am certain I am missing something fundamental.

Here the code for the unit

 

unit uMOP;

interface

uses  FMX.ListView.Types, FMX.ListView.Appearances, FMX.Edit, FMX.Dialogs, Classes,

      FMX.ListView.Adapters.Base, FMX.ListView, FMX.Types, System.UITypes, System.SysUTils;

type

    TListItemQtyBox = class(TListItemEmbeddedControl)

    public

      QtyBox : TEdit ;

      Constructor Create( const AOwner : TListItem); override;

      Destructor Destroy; override;

      procedure QtyOnClick(Sender : TObject);

      procedure KeyDown(Sender: TObject; var Key: Word; var KeyChar: WideChar; Shift: TShiftState);

 end;

implementation

procedure TListItemQtyBox.QtyOnClick(Sender: TObject);

begin

   MessageDlg('Clicked',TMsgDlgType.mtInformation,[TMsgDlgBtn.mbOK],0) //just for test purposes

end;

procedure TListItemQtyBox.KeyDown(Sender: TObject; var Key: Word; var KeyChar: Char; Shift: TShiftState);

begin

   QtyBox.Text:= keychar; //for test purposes

end;

constructor TListItemQtyBox.Create(const AOwner: TListItem);

begin

    inherited;

    QtyBox:= TEdit.Create(nil);

    QtyBox.Parent:= Container;

    QtyBox.Name:= 'eQty';

    QtyBox.Width:= 30;

    QtyBox.Align:= FMX.Types.TAlignLayout.Right;

    QtyBox.MArgins.Top:= 10;

    QtyBox.Margins.Bottom:= 5;

    QtyBox.OnClick:= QtyOnClick;

    QtyBox.OnKeyDown:= KeyDown;

end;

destructor TListItemQtyBox.Destroy;

begin

  // do more stuff here

end;

end.

 

 

From the app, this is what calls the creation of each line item

 

procedure TfrmMain.lvResultsUpdateObjects(const Sender: TObject;  const AItem: TListViewItem);

var

   eQty : TListItemQtyBox;

begin

   Case AItem.Purpose of

   TListItemPurpose.none:   begin 

            eQty:= AITem.Objects.FindObject('sQty') As TListItemQtyBox;

                              if not Assigned(eQty) then

                                begin

                                  eQty:= TListItemQtyBox.Create(AItem);

                                  eQty.QtyBox.Text:= '1';

                                end;

                            end;

   end;

end;


Viewing all articles
Browse latest Browse all 3212

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>