Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: Assigning OnClick Event Handler In TListItemImage Object....



Permlink Replies: 8 - Last Post: Apr 13, 2016 3:29 PM Last Post By: CARLOS EDUARDO ...
Thiago Silva


Posts: 37
Registered: 12/20/04
Assigning OnClick Event Handler In TListItemImage Object....
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 10, 2015 5:43 AM
Hi Everyone,

I have a issue where I need to insert a image inside a TListViewItem and trigger a Onclick event when it´ll be clicked. I looked for some examples without sucess. Any ideia to solv it?

Best regards,

Thiago.

procedure TfrmAdiciona_Itens.lstMainUpdateObjects(const Sender: TObject;
const AItem: TListViewItem);
const Item_Add = 'imgItem_Add';
Item_Remove = 'imgItem_Remove';
var FItemAdd: TListItemImage;
FItemRemove: TListItemImage;
FImage: TResourceStream;
begin

FItemAdd := AItem.Objects.FindObject(Item_Add) as TListItemImage;
if FItemAdd = Nil then
begin
FItemAdd := TListItemImage.Create(AItem);
FItemAdd.Name := Item_Add;
FItemAdd.Align:= TListItemAlign.Trailing;
FItemAdd.VertAlign:= TListItemAlign.Trailing;
FItemAdd.PlaceOffset.X:= 0;
FItemAdd.PlaceOffset.Y:= -5;
FItemAdd.Width:= 60;
FItemAdd.Height:= 18;
FItemAdd.OwnsBitmap := True;
FItemAdd.bitmap := Tbitmap.Create(0,0);
FImage := TResourceStream.Create(HInstance, 'item_add', RT_RCDATA);
FItemAdd.Bitmap.LoadFromStream(FImage);
end;

FItemRemove := AItem.Objects.FindObject(Item_Remove) as TListItemImage;
if FItemRemove = Nil then
begin
FItemRemove := TListItemImage.Create(AItem);
FItemRemove.Name := Item_Add;
FItemRemove.Align:= TListItemAlign.Trailing;
FItemRemove.VertAlign:= TListItemAlign.Trailing;
FItemRemove.PlaceOffset.X:= 25;
FItemRemove.PlaceOffset.Y:= -5;
FItemRemove.Width:= 60;
FItemRemove.Height:= 18;
FItemRemove.OwnsBitmap := True;
FItemRemove.bitmap := Tbitmap.Create(0,0);
FImage := TResourceStream.Create(HInstance, 'item_remove', RT_RCDATA);
FItemRemove.Bitmap.LoadFromStream(FImage);
end;

end;

Edited by: Thiago Silva on Nov 10, 2015 5:46 AM

Graham Murt

Posts: 70
Registered: 5/15/07
Re: Assigning OnClick Event Handler In TListItemImage Object....
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 10, 2015 8:54 AM   in response to: Thiago Silva in response to: Thiago Silva
Take a look at my ksComponents (specifically the ksTableView) - I think you;ll find this much easier to work with than the standard TListView.

https://github.com/gmurt/KernowSoftwareFMX

My ksListView component is now deprecated - the new TksTableView has taken over from TksListView as it no longer inherits from TCustomListView, this gives much more flexibility on what we can do.

Here's the code you can use to do what you need...

procedure TForm19.FormCreate(Sender: TObject);
var
  AItem: TksTableViewItem;
begin
  ksTableView1.BeginUpdate;
  try
    // add the title, subtitle, detail and accessory...
    AItem := ksTableView1.Items.AddItem('Main title', 'Subtitle', 'detail', TksAccessoryType.atMore);
    // draw a bitmap on the row...
    AItem.DrawBitmap(Image1.Bitmap, 100, 32, 32).ID := 'IMAGE';
  finally
    ksTableView1.EndUpdate;
  end;
end;
 
procedure TForm19.ksTableView1ItemClick(Sender: TObject; x, y: Single; AItem: TksTableViewItem; AId: string; ARowObj: TksTableViewItemObject);
begin
  // check if a row sub-object was clicked...
  if ARowObj <> nil then
  begin
    // was the object with the correct ID clicked...
    if ARowObj.ID = 'IMAGE' then
      ShowMessage('you clicked the image :-)');
  end;
end;


Here's a link to the full source for this demo...
https://dl.dropboxusercontent.com/u/24455058/Demo.zip

Thiago Silva wrote:
Hi Everyone,

I have a issue where I need to insert a image inside a TListViewItem and trigger a Onclick event when it´ll be clicked. I looked for some examples without sucess. Any ideia to solv it?

Best regards,

Thiago.

procedure TfrmAdiciona_Itens.lstMainUpdateObjects(const Sender: TObject;
const AItem: TListViewItem);
const Item_Add = 'imgItem_Add';
Item_Remove = 'imgItem_Remove';
var FItemAdd: TListItemImage;
FItemRemove: TListItemImage;
FImage: TResourceStream;
begin

FItemAdd := AItem.Objects.FindObject(Item_Add) as TListItemImage;
if FItemAdd = Nil then
begin
FItemAdd := TListItemImage.Create(AItem);
FItemAdd.Name := Item_Add;
FItemAdd.Align:= TListItemAlign.Trailing;
FItemAdd.VertAlign:= TListItemAlign.Trailing;
FItemAdd.PlaceOffset.X:= 0;
FItemAdd.PlaceOffset.Y:= -5;
FItemAdd.Width:= 60;
FItemAdd.Height:= 18;
FItemAdd.OwnsBitmap := True;
FItemAdd.bitmap := Tbitmap.Create(0,0);
FImage := TResourceStream.Create(HInstance, 'item_add', RT_RCDATA);
FItemAdd.Bitmap.LoadFromStream(FImage);
end;

FItemRemove := AItem.Objects.FindObject(Item_Remove) as TListItemImage;
if FItemRemove = Nil then
begin
FItemRemove := TListItemImage.Create(AItem);
FItemRemove.Name := Item_Add;
FItemRemove.Align:= TListItemAlign.Trailing;
FItemRemove.VertAlign:= TListItemAlign.Trailing;
FItemRemove.PlaceOffset.X:= 25;
FItemRemove.PlaceOffset.Y:= -5;
FItemRemove.Width:= 60;
FItemRemove.Height:= 18;
FItemRemove.OwnsBitmap := True;
FItemRemove.bitmap := Tbitmap.Create(0,0);
FImage := TResourceStream.Create(HInstance, 'item_remove', RT_RCDATA);
FItemRemove.Bitmap.LoadFromStream(FImage);
end;

end;

Edited by: Thiago Silva on Nov 10, 2015 5:46 AM

CARLOS EDUARDO ...

Posts: 1
Registered: 5/22/09
Re: Assigning OnClick Event Handler In TListItemImage Object....
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 13, 2016 3:29 PM   in response to: Graham Murt in response to: Graham Murt
Graham Murt wrote:
Take a look at my ksComponents (specifically the ksTableView) - I think you;ll find this much easier to work with than the standard TListView.

https://github.com/gmurt/KernowSoftwareFMX

My ksListView component is now deprecated - the new TksTableView has taken over from TksListView as it no longer inherits from TCustomListView, this gives much more flexibility on what we can do.

Here's the code you can use to do what you need...

procedure TForm19.FormCreate(Sender: TObject);
var
  AItem: TksTableViewItem;
begin
  ksTableView1.BeginUpdate;
  try
    // add the title, subtitle, detail and accessory...
    AItem := ksTableView1.Items.AddItem('Main title', 'Subtitle', 'detail', TksAccessoryType.atMore);
    // draw a bitmap on the row...
    AItem.DrawBitmap(Image1.Bitmap, 100, 32, 32).ID := 'IMAGE';
  finally
    ksTableView1.EndUpdate;
  end;
end;
 
procedure TForm19.ksTableView1ItemClick(Sender: TObject; x, y: Single; AItem: TksTableViewItem; AId: string; ARowObj: TksTableViewItemObject);
begin
  // check if a row sub-object was clicked...
  if ARowObj <> nil then
  begin
    // was the object with the correct ID clicked...
    if ARowObj.ID = 'IMAGE' then
      ShowMessage('you clicked the image :-)');
  end;
end;


Here's a link to the full source for this demo...
https://dl.dropboxusercontent.com/u/24455058/Demo.zip

Thiago Silva wrote:
Hi Everyone,

I have a issue where I need to insert a image inside a TListViewItem and trigger a Onclick event when it´ll be clicked. I looked for some examples without sucess. Any ideia to solv it?

Best regards,

Thiago.

procedure TfrmAdiciona_Itens.lstMainUpdateObjects(const Sender: TObject;
const AItem: TListViewItem);
const Item_Add = 'imgItem_Add';
Item_Remove = 'imgItem_Remove';
var FItemAdd: TListItemImage;
FItemRemove: TListItemImage;
FImage: TResourceStream;
begin

FItemAdd := AItem.Objects.FindObject(Item_Add) as TListItemImage;
if FItemAdd = Nil then
begin
FItemAdd := TListItemImage.Create(AItem);
FItemAdd.Name := Item_Add;
FItemAdd.Align:= TListItemAlign.Trailing;
FItemAdd.VertAlign:= TListItemAlign.Trailing;
FItemAdd.PlaceOffset.X:= 0;
FItemAdd.PlaceOffset.Y:= -5;
FItemAdd.Width:= 60;
FItemAdd.Height:= 18;
FItemAdd.OwnsBitmap := True;
FItemAdd.bitmap := Tbitmap.Create(0,0);
FImage := TResourceStream.Create(HInstance, 'item_add', RT_RCDATA);
FItemAdd.Bitmap.LoadFromStream(FImage);
end;

FItemRemove := AItem.Objects.FindObject(Item_Remove) as TListItemImage;
if FItemRemove = Nil then
begin
FItemRemove := TListItemImage.Create(AItem);
FItemRemove.Name := Item_Add;
FItemRemove.Align:= TListItemAlign.Trailing;
FItemRemove.VertAlign:= TListItemAlign.Trailing;
FItemRemove.PlaceOffset.X:= 25;
FItemRemove.PlaceOffset.Y:= -5;
FItemRemove.Width:= 60;
FItemRemove.Height:= 18;
FItemRemove.OwnsBitmap := True;
FItemRemove.bitmap := Tbitmap.Create(0,0);
FImage := TResourceStream.Create(HInstance, 'item_remove', RT_RCDATA);
FItemRemove.Bitmap.LoadFromStream(FImage);
end;

end;

Edited by: Thiago Silva on Nov 10, 2015 5:46 AM,

Graham Murt

Your component has rotated just right for me, its not functional demo, it does not fire the onclick event in relation to the object; Simply nothing appears;

Graham Murt

Posts: 70
Registered: 5/15/07
Re: Assigning OnClick Event Handler In TListItemImage Object....
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 10, 2015 8:58 AM   in response to: Thiago Silva in response to: Thiago Silva
Forgot the image... here's a screenshot of the demo...

https://dl.dropboxusercontent.com/u/24455058/demo.png

Thiago Silva wrote:
Hi Everyone,

I have a issue where I need to insert a image inside a TListViewItem and trigger a Onclick event when it´ll be clicked. I looked for some examples without sucess. Any ideia to solv it?

Best regards,

Thiago.

procedure TfrmAdiciona_Itens.lstMainUpdateObjects(const Sender: TObject;
const AItem: TListViewItem);
const Item_Add = 'imgItem_Add';
Item_Remove = 'imgItem_Remove';
var FItemAdd: TListItemImage;
FItemRemove: TListItemImage;
FImage: TResourceStream;
begin

FItemAdd := AItem.Objects.FindObject(Item_Add) as TListItemImage;
if FItemAdd = Nil then
begin
FItemAdd := TListItemImage.Create(AItem);
FItemAdd.Name := Item_Add;
FItemAdd.Align:= TListItemAlign.Trailing;
FItemAdd.VertAlign:= TListItemAlign.Trailing;
FItemAdd.PlaceOffset.X:= 0;
FItemAdd.PlaceOffset.Y:= -5;
FItemAdd.Width:= 60;
FItemAdd.Height:= 18;
FItemAdd.OwnsBitmap := True;
FItemAdd.bitmap := Tbitmap.Create(0,0);
FImage := TResourceStream.Create(HInstance, 'item_add', RT_RCDATA);
FItemAdd.Bitmap.LoadFromStream(FImage);
end;

FItemRemove := AItem.Objects.FindObject(Item_Remove) as TListItemImage;
if FItemRemove = Nil then
begin
FItemRemove := TListItemImage.Create(AItem);
FItemRemove.Name := Item_Add;
FItemRemove.Align:= TListItemAlign.Trailing;
FItemRemove.VertAlign:= TListItemAlign.Trailing;
FItemRemove.PlaceOffset.X:= 25;
FItemRemove.PlaceOffset.Y:= -5;
FItemRemove.Width:= 60;
FItemRemove.Height:= 18;
FItemRemove.OwnsBitmap := True;
FItemRemove.bitmap := Tbitmap.Create(0,0);
FImage := TResourceStream.Create(HInstance, 'item_remove', RT_RCDATA);
FItemRemove.Bitmap.LoadFromStream(FImage);
end;

end;

Edited by: Thiago Silva on Nov 10, 2015 5:46 AM

Thiago Silva


Posts: 37
Registered: 12/20/04
Re: Assigning OnClick Event Handler In TListItemImage Object....
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 10, 2015 9:05 AM   in response to: Graham Murt in response to: Graham Murt
Thank you for awswering!

Is it an open source component? To change my project it will take a long time. Do you have any temp solution for me?

Regards,

Thiago.
Graham Murt

Posts: 70
Registered: 5/15/07
Re: Assigning OnClick Event Handler In TListItemImage Object....
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 10, 2015 11:37 AM   in response to: Thiago Silva in response to: Thiago Silva
Yes, free open source.

My only solution is this...
- crack open a beer or glass of wine
- start replacing with TksTabelview

:-)

Thiago Silva wrote:
Thank you for awswering!

Is it an open source component? To change my project it will take a long time. Do you have any temp solution for me?

Regards,

Thiago.

Edited by: Graham Murt on Nov 10, 2015 1:47 PM
Van Swofford

Posts: 397
Registered: 6/28/03
Re: Assigning OnClick Event Handler In TListItemImage Object.... [Edit]
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 10, 2015 2:06 PM   in response to: Graham Murt in response to: Graham Murt
Graham Murt wrote:

Yes, free open source.

My only solution is this...
- crack open a beer or glass of wine
- start replacing with TksTabelview

How about TksTableView? And perhaps reverse the order, and open the
beer second? :-)

--
Cheers,
Van

"Good judgment comes from experience, and a lot of that comes from bad
judgment." - Will Rogers
Graham Murt

Posts: 70
Registered: 5/15/07
Re: Assigning OnClick Event Handler In TListItemImage Object.... [Edit]
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 10, 2015 2:30 PM   in response to: Van Swofford in response to: Van Swofford
Whichever order works well for you :-)

I'm releasing updates daily so if there's anything you need added, let me know.

Twitter: @KsComponents

Kind regards,
Graham

Van Swofford wrote:
Graham Murt wrote:

Yes, free open source.

My only solution is this...
- crack open a beer or glass of wine
- start replacing with TksTabelview

How about TksTableView? And perhaps reverse the order, and open the
beer second? :-)

--
Cheers,
Van

"Good judgment comes from experience, and a lot of that comes from bad
judgment." - Will Rogers
Thiago Silva


Posts: 37
Registered: 12/20/04
Re: Assigning OnClick Event Handler In TListItemImage Object.... [Edit]
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 11, 2015 4:20 AM   in response to: Graham Murt in response to: Graham Murt
Thank you everyone !!!

I´ll following the sugestions and may be drink a glass of wine before, during and after... It will be hard work!

Regards,

Thiago.
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02