[solved] Inherited TCustomStringGrid component : add a property in TGridColumn lazarus / 31-LCL ---------------------------------------------------------------------- Selzig Hem · 2011-11-21 10:07 Hello, In an inherited  TCustomStringGrid component, I would add a property in TGridColumn = class (TCollectionItem) (which is originally defined in /lcl/grids.pas). Is it possible in a simple way? Regards. Gilles ---------------------------------------------------------------------- Selzig Hem · 2011-11-21 11:07 Hello, I found a  part of the answer in this forum : http://forum.lazarus.freepascal.org/index.php/topic,12562.0.html. It's complicated as I expected... and not usable. Regards. Gilles ---------------------------------------------------------------------- Blaazen · 2011-11-21 13:26 What properties are you planning to add to columns? Adding them directly to TGridCoumn is probably impossible, it is too complex. Maybe you can have your own dynamic structure (list) of your properties and you can add/remove them each time you will add/remove column. Then you will need to introduce your own Add/RemoveColumn methods which will manage adding/removing both columns (natively) and your properties (your own list). ---------------------------------------------------------------------- wp · 2011-11-21 14:53 Derive your new column from TGridColumn and override the grid's CreateColumns method Code: [Select]type   TMyGridColumn = class(TGridColumn)   private     FNewProperty : integer;   published     property NewProperty: integer read FNewProperty write FNewProperty;   end;   TMyStringGrid = class(TCustomStringGrid)   protected     function CreateColumns: TGridColumns; override;   end;   function TMyStringGrid.CreateColumns: TGridColumns;   begin     Result := TGridColumns.Create(Self, TMyGridColumn); end;       The grid component is well-designed and has many virtual methods which allow you to change almost everything. Have a look at the source code. If you need an example see my posting at http://www.lazarus.freepascal.org/index.php/topic,15259.0.html. It has some issues, though; but these are not related to your question. ---------------------------------------------------------------------- Selzig Hem · 2011-11-22 08:08 Hello, thanks for yours answers. @wp : It works fine. I am not sure that the grid component is well-designed. Code: [Select]With StringGrid1 do begin  Cells[1,1] := 'Test'+#0+'anything';  Showmessage(IntToStr(length(Cells[1,1])); end; The result is 4 ! If Cells is really an AnsiString why does not it accept null characters ? There are other problems. Again thanks for your solution. I tried something similar but it did not work. I guess it's still a problem to recompile the component: it is common when I change or add some properties or methods. A simple compilation of the component is not always sufficient. To be sure of the result, I have to  recompile Lazarus with the option Clean All + Build ... and this requires a lot of time... so I do not recompile lazarus systematically. Regards. Gilles ---------------------------------------------------------------------- wp · 2011-11-22 11:27 Sorry, I cannot comment much because I do not know exactly what you want to do. I get the impression that you modify TStringGrid directly. You shouldn't do that, you should always create a new component derived from the one that you want to change, and override its virtual methods. In that sense, the grids are really well-designed because you can change almost everything this way. ---------------------------------------------------------------------- Selzig Hem · 2011-11-23 09:12 Hello wp, the problem is solved. Your answer works fine. I added just two comments : It is (often) necessary to completely rebuild lazarus for the changes of the components are taken into account. It's very heavy... and that's why one of my tests similar to yours, did not seem to work.The StringGrids are not as well designed as that. Impossible to directly enter strings with null characters (exemple I added). The Kgrid does it very well. Now the cells are strings ... but we can not fill them as string.Regards. Gilles ---------------------------------------------------------------------- jesusr · 2011-11-24 08:21 Quote from: Selzig Hem on November 22, 2011, 09:08:48 amI am not sure that the grid component is well-designed. Code: [Select]With StringGrid1 do begin  Cells[1,1] := 'Test'+#0+'anything';  Showmessage(IntToStr(length(Cells[1,1])); end; The result is 4 ! If Cells is really an AnsiString why does not it accept null characters ? There are other problems. Under the scene, the stringgrid uses pchar which supposedly in addition of other things, should save some bytes on big grids. Anyway changing to use string instead of pchar it's almost trivial, but your example makes me wonder if it's really necesary. A grid that uses ansistring should show in your case "Test?anything" is that the intended behaviour? On the other hand if it only shows "Test" then it would be treating the ansistring as pchar which is cheating too. Editing such cell would lose data, I'm guessing. So how could it something like your example be treated the right way? ---------------------------------------------------------------------- Selzig Hem · 2011-11-26 10:16 Hello Jesus, I hope what I write is understandable. My english is really bad. First I want to say that I regard Lazarus as an excellent IDE that I use daily in my work. However, your reaction is the same as your team has had when I asked that we can put an underscore character (&) in the title.caption of columns. What's the use? The problem is not there ... but it is the same. The title.caption is a caption ... It should work like any caption. The analogy is the same. The cells are strings. They should work just like any other string. "Anyway changing to use string instead of pchar it's almost trivial". Probably, but not for maintenance of my component if it is me who incorporates it into my component (that  currently is inherited of  TCustomStringGrid). I've had to incorporate sorting and searching on the columns header, a real multi-selection [eg Rows 1, 8, 9 and 25], basic things that should be incorporated to the users of Lazarus. I remember that Columns.visible only works since 0.9.29 ! Nobody used invisible cells in TStringGrids before 0.9.29 ? I said this bug  in the bugtracker when I used  0.9.26 version. I believe that TCustomStringGrid  is the inheritor poor of Lazarus. Let me also say that on the use of string, I do not understand why the function Pos (or strpos) does not detect either null characters. Here too, I guess it has no interest. StrReplace function could be a solution to my problem but it is a maddeningly slow. To answer your question precisely, to manage my databases, I use Internet connections that are not always persistent. This forbids the use of  Connector-dataset-datasource-DBGrid because in case of rupture of the connection, the DBGrid is erased. So I use a TStringGrid.  This allows me to load my tables with 2 steps. Let's say the first 100 records in the main thread and the rest in a parallel thread. Thus, my form is not frozen.  An Internet connection is slower than an local access. I use parallel thread to get a real Fetch. Now, suppose that in my component 'dbStringGrid', from my database, I want to load the blobs (the strings only - without displaying the images) .  Then I want when the mouse is over the grid lines, the images appear instantly in a TImage placed on the Form. The blobs contain null characters.  I had to associate my StringGrid to an array of String (or more "badly" with TObject) to get the desired effect. This is certainly unusual as managing ... But why can not I do it simply with Lazarus? Regards. Gilles ---------------------------------------------------------------------- jesusr · 2011-11-26 20:22 QuoteWhat's the use? The problem is not there ... but it is the same. The title.caption is a caption ... It should work like any caption. The reaction was, I think, normal, a & is associated to a shortcut that trigger some action, is not for decorating, I agree we can disagree on this. But to me, shortcuts defined this way are handled by the control that contain such caption, for example a label will focus the associated component, a button will click, a menu will trigger it's action, etc. for grid colums "&" was asked but without related action . QuoteThe analogy is the same. The cells are strings. They should work just like any other string. StringGrid do show and edit strings. Editors are not prepared to handle #0 in the middle of strings that I know, even if they are ansi strings. Forcing it's use when you don't know how the control will react is not good, as I don't know how the editor will react, I didn't plan to handle this situation.  but... as I wrote before, it's very easy to me to change this behaviour so it will use real string instead of pchar, I expressed my doubt about how it will work, meanly that I find there will be two cases, but you do nothing to resolve my doubt. Quote I've had to incorporate sorting and searching on the columns header, a real multi-selection [eg Rows 1, 8, 9 and 25], basic things that should be incorporated to the users of Lazarus.Sorting is incorporated, and even can be selected as default action when clicking column title, searching is basically application specific, what would the grid do when it by itself is not interested in what it contains?. Multiselection maybe useful, indeed I use multiselection in some application and I find it much better to store selected status in user data than in the cells, so multiselect is not implemented by default, nobody ever asked for it, that I know too. QuoteI remember that Columns.visible only works since 0.9.29 ! Nobody used invisible cells in TStringGrids before 0.9.29 ? I said this bug  in the bugtracker when I used  0.9.26 version. I believe that TCustomStringGrid  is the inheritor poor of Lazarus. It seems not. There are multiple reasons to not fix everything immediately, the available free time it's perhaps the more common, and sad but true, when it took long time to work in bugs reports many have accumulated, and some are more time demanding than others, some receive more attention, and it may happen that some very easy to fix are "obscured" by others, in reality there are may reasons. That particular case I don't remember, if the bug still exists please direct me to the bug report. Quote I believe that TCustomStringGrid  is the inheritor poor of Lazarus. Sorry I don't quite understand this. QuoteNow, suppose that in my component 'dbStringGrid', from my database, I want to load the blobs (the strings only - without displaying the images) .  Then I want when the mouse is over the grid lines, the images appear instantly in a TImage placed on the Form. The blobs contain null characters.  I had to associate my StringGrid to an array of String (or more "badly" with TObject) to get the desired effect. This is certainly unusual as managing ... But why can not I do it simply with Lazarus?And have you asked yourself if this is the best approach you can take?, why not for example use the grids.Objecs[x,y] property and store the blob data in a object. Every solution depends on your point of view of course and I might be missing something obvious, but form your description grids.Objecs[x,y] seems a much better choice. Jesus Reyes A. ---------------------------------------------------------------------- Selzig Hem · 2011-11-27 11:56 Hello Jesus, As I said, in the software that I currently developing, my approach is unusual because the circumstances require it. I consider a language as Lazarus must be versatile to successfully challenge. If I want to emphasize the fluidity of a software, cut and thread my access to a database whose connection is not persistent, I must be able to do it. And with Lazarus, I can do this. BUT, now as a developer, I need to focus on the process logic ("business rules"). When I use your StringGrids, 80% of the time is assigned to create basic functions for the component: the multiselect only works for continuous block. This is very inadequate. In your work, all your selections in a grid form a continuous block? Why is it necessary to reinvent the wheel? This can not be integrated into the basic StringGrid? Therefore spend less time : bugs : http://62.166.198.202/view.php?id=20607, http://62.166.198.202/view.php?id=20494, waiting, waiting.... I leave you to your beliefs ... and your work. I think I'll learn to do without Lazarus that I practice since version 0.9.24.  As a developer, it is not productive enough for the reasons I explained. The best. Bye. Gilles ---------------------------------------------------------------------- Avishai · 2011-11-27 12:20 Maybe if you offer a bounty someone can write this special code for you. ---------------------------------------------------------------------- Selzig Hem · 2011-11-27 14:53 Hello Avishai, For me the discussion is closed: It's been three years since I worked with Lazarus because Borland  abandoned Kylix. In Lazarus, the "developed" components are missing. The product is very nice but in my opinion poorly controlled. Compatibility with Delphi 7 is not (more) be a target or a straitjacket. Delphi 7 is finished. It's FireMonkey now. To give scale to the product, some components need to be more prepared ... In production, it is not rentalisable even pay someone to do the job. In my case, the job is done and functional but it required too much time. In addition, it lacks many of the add-on of modern IDE that facilitate and automate the work. It's already a huge defect in productivity: It remained as Delphi 7. Given the small size of the community, its ever-changing code (and therefore non-stabilized), requires that the Lazarus team creates these components. Well, I stop here my reasons for quitting: I already expressed my fears in vain ... I respect the work of the team lazarus but the conclusion is that I can not productively use this platform in the time available for my project. I agree also willing to admit my failure. I get the desired result... but too slowly. I wish good luck to the team which I will try to continue to monitor the progress of the IDE. Regards. Gilles ---------------------------------------------------------------------- jesusr · 2011-11-27 19:16 Quote from: Selzig Hem on November 27, 2011, 12:56:14 pmHello Jesus, As I said, in the software that I currently developing, my approach is unusual because the circumstances require it. I consider a language as Lazarus must be versatile to successfully challenge. If I want to emphasize the fluidity of a software, cut and thread my access to a database whose connection is not persistent, I must be able to do it. And with Lazarus, I can do this. What seems unusual is the way you want to solve the problems, but of course we will not discuss this it's all about developer preferences, but if you want to include something in the grid and it is of general use patches are welcomed. Or given the time and a good spec I will try to implement. QuoteBUT, now as a developer, I need to focus on the process logic ("business rules"). When I use your StringGrids, 80% of the time is assigned to create basic functions for the component: the multiselect only works for continuous block. This is very inadequate. I'm sorry, the grid is not a magical box that has all and every feature needed or imagined, we can join all efforts and make it happen, but currently it's not, so some work is needed from the developer part and do the work that is missing. unfortunately one can only came to one conclusion, no effort seems enough, every developer has it's own idea on what a component should do or behave and if you make happy some most certainly will make others sad. Quote In your work, all your selections in a grid form a continuous block? Why is it necessary to reinvent the wheel? This can not be integrated into the basic StringGrid? Therefore spend less time : bugs : http://62.166.198.202/view.php?id=20607, http://62.166.198.202/view.php?id=20494, waiting, waiting.... In all except one where I, with few lines of code, made it work the way I need, so I though that is not that bad for a generic grid. The problem might be in the details and what works perfect for me may not work nice for you. But lets see, have you ever requested a multiselect feature for the grid?, if so please direct me to the post or bug tracker request where you have set forth the specs for such feature. That's to say that I'm not closed to add features. About the bug reports you mention, 20494 submitted by you on 2011-10-16 was set target version 1.2 by manager (and take into a count 1.0 is not yet released) I resolved the problem a day after and you give feedback on 2011-10-24 that's 7 days after I fixed it, a correction by me 4 days after and until now I don't know if it worked because you have not closed the report. About 20607 submitted on 2011-11-01, the manager hadn't time to set the target but anyway I fixed it 3 days after and still the same result I don't know if the fix worked for you because you have not closed the report. I think I could say the same: waiting, waiting.... of course nobody has to reply me that I don't fix all bugs that quick QuoteI leave you to your beliefs ... and your work.  I think I'll learn to do without Lazarus that I practice since version 0.9.24.  I don't fully understand the sense of this so I won't comment. QuoteAs a developer, it is not productive enough for the reasons I explained. The best. Bye. Gilles I'm sad, I wish it would be as productive for other as it is for me ... Regards. Jesus Reyes A. ---------------------------------------------------------------------- Selzig Hem · 2011-11-27 19:39 Hello Jesus, I do not agree with you but thank you for your answers. Regards. Gilles