TString grid copy and paste UTF-8 Ansi issue lazarus / 31-LCL ---------------------------------------------------------------------- tr_escape · 2017-10-30 12:55 Hello LCL team, I am trying to paste some datas into TStringGrid of lazarus but Turkish characters is not pasting. I tried to change some code page etc but not working. But if I paste in the cell editing mode it is working. Is there any another setting? Best regards Lazarus 1.9.0 Fpc 3.1.1 (trunk) ---------------------------------------------------------------------- wp · 2017-10-30 13:39 I just tried with some Turkish text copied from a Turkish website, and it is working here without any problems (Win 10/64 bit, Laz trunk / fpc 3.04 (32 bit)). Please describe in more detail: "Turkish characters is not pasting" - does this mean that normal ASCII characters (< #128) are pastring correctly? How do the Turkish characters appear in the grid? Upload a screenshot. Are you sure that the text that you paste is UTF8-encoded? (Although: it should be since pasting works for you in edit mode). Or is nothing pasted at all? How do you paste? By code? Or by keyboard? In the latter case you should know that SHIFT-INSERT is working only in edit mode, use CTRL-V instead. ---------------------------------------------------------------------- tr_escape · 2017-10-30 13:56 I am using windows 7 64 bit but lazarus is 32 bit. (I didn't try in Linux for now) I used ctrl+v only but one of is I select only a cell not in edit mode other is copied one-by-one for each cell with editing mode. ---------------------------------------------------------------------- tr_escape · 2017-10-30 14:19 Additional info: I tried in Lubuntu copied from web site it is working but same text in windows 7 not working. That copied: Türkçe ya da Türk dili, batıda Balkanlar’dan başlayıp doğuda Hazar Denizi sahasına kadar konuşulan Altay dillerinden biridir. Yaşı, en eski hesaplara göre 8500 olan Türkçe, bugün yaşayan Dünya dilleri arasında en eski yazılı belgelere sahip olan dildir. https://tr.wikipedia.org/wiki/Türkçe Edit: Also I checked diff both sources of lazarus's lcsvutils.pas that LoadFromCSVStream function is same. ---------------------------------------------------------------------- JuhaManninen · 2017-10-30 14:33 Quote from: tr_escape on October 30, 2017, 03:19:39 pmI tried in Lubuntu copied from web site it is working but same text in windows 7 not working. Copy/paste from a web page does not work either? Maybe you use -dDisableUTF8RTL. See:  http://wiki.freepascal.org/Lazarus_with_FPC3.0_without_UTF-8_mode Otherwise it is difficult to explain. ---------------------------------------------------------------------- wp · 2017-10-30 15:47 Could you try this experiment: Add a button to the form with this OnClick event handler: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i uses  Lcltype, Lclintf, clipbrd; procedure TForm1.Button1Click(Sender: TObject);var  i: Integer;  rs: RawByteString;  s: String;begin  StringGrid1.Cells[1, 1] := 'AsText';  StringGrid1.Cells[1, 2] := 'AsHTML';  StringGrid1.Cells[1, 3] := 'Format';  StringGrid1.Cells[1, 4] := 'Raw';   SetLength(rs, 100);  Clipboard.GetTextBuf(PChar(rs), 100);  s := '';  for i:=1 to Length(rs) do    if rs[i] < #128 then    s := s + rs[i] else      s := s + '.';   StringGrid1.Cells[2, 1] := Clipboard.AsText;  StringGrid1.cells[2, 2] := Clipboard.GetAsHtml(true);  StringGrid1.Cells[2, 3] := IntToStr(PredefinedClipboardFormat(pcfText));  StringGrid1.Cells[2, 4] := s;end; This code pastes the text into cell (2,1), reads the clipboard format identifier used when pasting the text (cell 2,3), and displays the clipboard's raw bytes as ASCII characters in cell (2, 4). If the clipboard contains UTF8-encoded text then two or three dots should be shown in place of the "ü", "ç" and other Turkish characters. The format identifier is 13 in my case. See my screenshot as an example when pasteing is working correctly. I copied the text to be pasted from your previous post. Please try this also, maybe Excel is doing something weird. Cell (2,2) is pasted as HTML. Does this work for you? For me it does. BTW, Windows7 in my VM is behaving correctly either. ---------------------------------------------------------------------- tr_escape · 2017-10-31 04:58 thank you for your support. I tried it worked for me also but if I paste from ctrl+v it is not working again. I think I will not accept ctrl+v on the stringgrid for now. I'll create a popup menu for paste. ---------------------------------------------------------------------- balazsszekely · 2017-10-31 05:26 What if you do an explicit typecast just before paste? Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.StringGrid1KeyDown(Sender: TObject; var Key: Word;  Shift: TShiftState);var  Str: String;begin  if (Key = VK_V) and (ssCtrl in Shift) then  begin    if Clipboard.HasFormat(CF_Text) then    begin    Str := ClipBoard.AsText; //this line should do the job(FPC 3.0.0+)    StringGrid1.Cells[StringGrid1.Col, StringGrid1.Row] := Str;    end;  end;end; ---------------------------------------------------------------------- tr_escape · 2017-10-31 05:36 Quote from: GetMem on October 31, 2017, 06:26:17 amWhat if you do an explicit typecast just before paste? Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.StringGrid1KeyDown(Sender: TObject; var Key: Word;  Shift: TShiftState);var  Str: String;begin  if (Key = VK_V) and (ssCtrl in Shift) then  begin    if Clipboard.HasFormat(CF_Text) then    begin    Str := ClipBoard.AsText; //this line should do the job(FPC 3.0.0+)    StringGrid1.Cells[StringGrid1.Col, StringGrid1.Row] := Str;    end;  end;end; No it is not changed behaving like as manuel paste as in the picture of posted by mine. The other issue is Tstringgrid.SavetoFile(filename); function is taking a lot of time because of my table is little bit big. 5000*4 datas take 1 minute 14 sec in debug mode. I think xml format the reason of slowness so I changed to Tstringgrid.SaveToCSVFile(filename); csv format it takes about 1 sec. xml data size 792KB csv is 200KB this means data size isn't main reason of this slowness. Is there any way to use fast this xml file? ---------------------------------------------------------------------- wp · 2017-10-31 07:47 Quote from: tr_escape on October 31, 2017, 05:58:01 amI tried it worked for me also but if I paste from ctrl+v it is not working again. These are the sources of TStringGrid.DoPasteFromClipboard (which is called when you press Ctrl-V): Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TCustomStringGrid.DoPasteFromClipboard;begin  // Unpredictable results when a multiple selection is pasted back in.  // Therefore we inhibit this here.  if HasMultiSelection then    exit;   if EditingAllowed(Col) and Clipboard.HasFormat(CF_TEXT) then begin    SelectionSetText(Clipboard.AsText);  end;end; This is getting the clipboard by calling Clipboard.AsText - which is working correctly for you (if I understood you correctly). Then the text is passed to SelectionSetText: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TCustomStringGrid.SelectionSetText(TheText: String);var  StartCol,StartRow: Integer;  Stream: TStringStream;   procedure LoadTSV(Fields: TStringList);  var    i, aCol, aRow: Integer;    NewValue: string;  begin    if StartRow "Custom Option", and type "-gw2" (without quotes) either in the line "Stored in project" or "Stored in session of project". This will activate dwarf debug information in your project and all modules used (except rtl/fcl). Therefore you will be able to trace into LCL routines and to check what's happening there.