Recent

Author Topic: <Solved> Cannot store TBookmark in ListItem.Data anymore  (Read 3286 times)

slai

  • New Member
  • *
  • Posts: 25
<Solved> Cannot store TBookmark in ListItem.Data anymore
« on: March 08, 2016, 11:38:44 am »
Hy together

Today i've installed Lazarus 1.6. Since then i have the issue that i e.g. this code line
Code: Pascal  [Select][+][-]
  1. aitem.Item[zaehler2].Data := tempquery.GetBookmark;
tempquery is an ZeosQuery (TZQuery)
aitem is TListItems.

is not compiling anymore with the error:
Error: Incompatible type for arg no. 1: Got "TBytes", expected "Pointer"

This was working with Lazarus 1.4.4, i think it could be because of fpc version change?
Does anyone of you have the same issues? Was there a change of .data property of a ListItem to Pointer?

Thx for any help!
« Last Edit: March 08, 2016, 07:43:11 pm by slai »

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11455
  • FPC developer.
Re: Cannot store TBookmark in ListItem.Data anymore
« Reply #1 on: March 08, 2016, 04:12:54 pm »
TBookmark changed. The same change happened in Delphi.

balazsszekely

  • Guest
Re: Cannot store TBookmark in ListItem.Data anymore
« Reply #2 on: March 08, 2016, 05:34:44 pm »
@slai
You can do something like this:
Code: Pascal  [Select][+][-]
  1. type
  2.   TData = class(TObject)
  3.     FBookMark: TBookMark;
  4.     //add other stuff here if necessary
  5.   end;
  6. ...
  7.  
  8. //assign bookmark to TListItem
  9. procedure TForm1.Button1Click(Sender: TObject);
  10. var
  11.   Data: TData;
  12. begin
  13.   Data := TData.Create;
  14.   Data.FBookMark := ZQuery1.Bookmark;
  15.   //...other data
  16.   ListView1.Items.Item[X].Data := Data; //replace X
  17. end;
  18.  
  19. //get bookmark from TListItem
  20. procedure TForm2.Button1Click(Sender: TObject);
  21. var
  22.   Data: TData;
  23. begin
  24.   Data := TData(ListView1.Items.Item[X]) //replace X
  25.   ZQuery1.BookMark := Data.FBookMark;
  26.   //...other data
  27. end;

Don't forget to free Data when you delete a TListItem!

slai

  • New Member
  • *
  • Posts: 25
Re: Cannot store TBookmark in ListItem.Data anymore
« Reply #3 on: March 08, 2016, 07:33:20 pm »
Hy GetMem

Thx a lot, didn't thought about a wrapper class  8)
I now created a class that takes a bookmark in the constructor so i directly can create the object itself then.

class:
Code: Pascal  [Select][+][-]
  1. unit bookmarkHelper;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, db;
  9.  
  10. type
  11.  
  12.   TData = class(TObject)
  13.     FBookMark: TBookMark;
  14.     Constructor Init(bMark : TBookMark);
  15.   end;
  16.  
  17. implementation
  18.  
  19. Constructor TData.Init(bMark : TBookMark);
  20. begin
  21.      FBookMark := bMark;
  22. end;
  23.  
  24. end.  

Usage:
Code: Pascal  [Select][+][-]
  1. aitem.Item[aitem.Count-1].Data := TData.Init(ZTable.GetBookmark);

Thinking now of a destructor and to handle freeing memory automatically when the object isn't used anymore.

But anyway, thx a lot!

mangakissa

  • Hero Member
  • *****
  • Posts: 1131
Re: <Solved> Cannot store TBookmark in ListItem.Data anymore
« Reply #4 on: March 09, 2016, 09:18:18 am »
It's a good point of view.
But why not save the primary key in property data with pointer(id) and use it in a locate. Bookmarks are not working anymore if data is changed in the dataset.
Lazarus 2.06 (64b) / FPC 3.0.4 / Windows 10
stucked on Delphi 10.3.1

 

TinyPortal © 2005-2018