* * *

Author Topic: Stringgrid removes quotes  (Read 800 times)

Snus

  • Newbie
  • Posts: 4
Stringgrid removes quotes
« on: January 31, 2018, 01:04:36 pm »
Hello. When I paste text in double quotes to stringgrid quotes are automatically removed. How to avoid it?
(Since upgrade to Lazarus 1.8.0)

Bart

  • Hero Member
  • *****
  • Posts: 2862
    • Bart en Mariska's Webstek
Re: Stringgrid removes quotes
« Reply #1 on: January 31, 2018, 01:39:53 pm »
I cannot reproduce that in current trunk.
If I paste "test" into a cell, the quotes are preserved.
Just in case you mean "" by double quotes: ""test"" also pastes as expected.

My stringrid options are default + goEdit.

Please be more precise: what is it exactly that you do?
On what OS/Widgetset are you?
Can you attach a sample application that reproduces the issue?

Bart

Snus

  • Newbie
  • Posts: 4
Re: Stringgrid removes quotes
« Reply #2 on: January 31, 2018, 01:56:53 pm »
Sure.

https://drive.google.com/file/d/14syWeg-lp_u7vXzmN479fK6aSKWae_Qe/view?usp=sharing

Do not open cell editor with double click. Single click to select cell

Win8, LCL all default. lazarus x32
« Last Edit: January 31, 2018, 01:59:09 pm by Snus »

Bart

  • Hero Member
  • *****
  • Posts: 2862
    • Bart en Mariska's Webstek
Re: Stringgrid removes quotes
« Reply #3 on: January 31, 2018, 06:08:31 pm »
First of all, do not include the actual executable in the archive, second please attach the zipped sources to your post in this forum, it's so much easier. Also .rar cannot be opened on Windows without external applications, please use .zip.

I built and ran you project, and it works as expected.
See attached screenshot.

Bart

Thaddy

  • Hero Member
  • *****
  • Posts: 5393
Re: Stringgrid removes quotes
« Reply #4 on: January 31, 2018, 06:24:37 pm »
.rar cannot be opened on Windows without external applications, please use .zip.
rar is also hard to open on Linux without extra software. Don't use it. There is no reason for it. And it is proprietary software. And the compression is '80's like.
« Last Edit: January 31, 2018, 06:27:42 pm by Thaddy »
High(Methusalem) - 1;

GetMem

  • Hero Member
  • *****
  • Posts: 2750
Re: Stringgrid removes quotes
« Reply #5 on: January 31, 2018, 06:40:04 pm »
I can reproduce the issue and in my opinion is a bug. If you click once to a cell a red "focused rectangle" appears(image1) and the paste doesn't work correctly. If you click again or doubleclick (image2) the StringGrid goes into edit mode and the text is pasted correctly. 

One solution is to add goAlwaysShowEditor to Options:
Code: Pascal  [Select]
  1. StringGrid1.Options := StringGrid1.Options + [goEditing, goAlwaysShowEditor];

Bart

  • Hero Member
  • *****
  • Posts: 2862
    • Bart en Mariska's Webstek
Re: Stringgrid removes quotes
« Reply #6 on: January 31, 2018, 07:13:57 pm »
I see.
The stringgrid does not have goEdit in Options, it should not be writeable at all.

Anyhow, when you do not have the editor open, pasting assumes you paste multiple cells, and treats the text on the clipboard as a CSV stream.
Processing the text as CSV removes the quote chars.

Please file a bugreport.

Bart
« Last Edit: January 31, 2018, 07:29:15 pm by Bart »

Snus

  • Newbie
  • Posts: 4
Re: Stringgrid removes quotes
« Reply #7 on: February 01, 2018, 10:10:04 am »
>and treats the text on the clipboard as a CSV stream
Well. It is definitely a bug. Why it doesn't copy to csv format than?
Here is a copy-paste from one row to another

>Please file a bugreport.
ok

wp

  • Hero Member
  • *****
  • Posts: 4213
Re: Stringgrid removes quotes
« Reply #8 on: February 01, 2018, 01:36:44 pm »
I think cells which contain tabs, linebreaks or quotes must be quoted when copying to the clipboard: tab is the column separator, linebreak the row separator, and quotation marks are the quoting identifiers. The current grid code does not take care of the quote case.

Open grids.pas, find procedure TCustomStringGrid.CopyCellRectToClipboard and add the condition pos('"', s) > 0 to the local function QuoteText. The entire function should read now like this:

Code: Pascal  [Select]
  1.   function QuoteText(s: string): string;
  2.   begin
  3.     DoCellProcess(aCol, aRow, cpCopy, s);
  4.     if (pos(#9, s)>0) or
  5.        (pos(#10, s)>0) or
  6.        (pos(#13, s)>0) or
  7.        (pos('"', s)>0)                   // <--- NEW
  8.     then
  9.       result := AnsiQuotedStr(s, '"')
  10.     else
  11.       result := s;
  12.   end;

With this modifcation, copy & and paste within the grid and also to and from Excel works correctly for me, also for these rare cases for which a cell contains tabs, lineendings, and quotes.
Lazarus trunk / fpc 3.0.4 / all 32-bit on Win-10

Bart

  • Hero Member
  • *****
  • Posts: 2862
    • Bart en Mariska's Webstek
Re: Stringgrid removes quotes
« Reply #9 on: February 01, 2018, 03:47:56 pm »
The problem is also in the method that does the copying.
It has a parameter TheText, which has the fully quotet text in it.
Nevertheless it always strips quotes upon pastes.

Bart

PS. Better continue the discussion in the bugtracker.

Snus

  • Newbie
  • Posts: 4
Re: Stringgrid removes quotes
« Reply #10 on: February 02, 2018, 04:45:27 pm »

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus