Recent

Author Topic: [SOLVED]: RichMemo to/from Db  (Read 244 times)

minkob

  • New Member
  • *
  • Posts: 13
[SOLVED]: RichMemo to/from Db
« on: September 14, 2019, 09:08:00 am »
Hi.
I am trying to read/write from/to RichMemo as a Blob.
Reading from db and writing to RichMemo works fine (btRead)
but writing to db from RichMemo (btWrite) fails with StackOverflow.

Code: Pascal  [Select]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, db, sqldb, IBConnection, Forms, Controls, Graphics,
  9.   Dialogs, StdCtrls, RichMemo;
  10.  
  11. type
  12.  
  13.   { TForm1 }
  14.  
  15.   TForm1 = class(TForm)
  16.     btRead: TButton;
  17.     btWrite: TButton;
  18.     DataSource1: TDataSource;
  19.     IBConnection1: TIBConnection;
  20.     RichMemo1: TRichMemo;
  21.     RichMemo2: TRichMemo;
  22.     SQLQuery1: TSQLQuery;
  23.     SQLTransaction1: TSQLTransaction;
  24.     procedure btReadClick(Sender: TObject);
  25.     procedure btWriteClick(Sender: TObject);
  26.   private
  27.  
  28.   public
  29.  
  30.   end;
  31.  
  32. var
  33.   Form1: TForm1;
  34.  
  35. implementation
  36.  
  37. {$R *.lfm}
  38.  
  39. { TForm1 }
  40.  
  41. procedure TForm1.btReadClick(Sender: TObject);    //this works fine
  42. var stream: TMemoryStream;
  43. begin
  44.      stream:= TMemoryStream.Create;
  45.   try
  46.       SQLQuery1.Close;
  47.       SQLQuery1.SQL.Text:= 'select TEXTBLOB from PRIKAZY where PORCIS = 5';
  48.       SQLQuery1.Open;
  49.       TBlobField(SQLQuery1.FieldByName('TEXTBLOB')).SaveToStream(stream);
  50.       stream.Position:= 0;
  51.       RichMemo1.Lines.LoadFromStream(stream);
  52.     finally
  53.       stream.Free;
  54.     end;
  55. end;
  56.  
  57. procedure TForm1.btWriteClick(Sender: TObject);   //does not work
  58. var stream: TMemoryStream;
  59. begin
  60.   IBConnection1.Connected:= true;
  61.   SQLTransaction1.Active:= true;
  62.   stream:= TMemoryStream.Create;
  63.   try
  64.     RichMemo2.Lines.SaveToStream(stream);
  65.     stream.Position:= 0;
  66.     SQLQuery1.Open;
  67.     SQLQuery1.SQL.Text:= 'update PRIKAZY set TEXTBLOB=:TEXTBLOB where PORCIS = 5';  //here it fails
  68.     SQLQuery1.ParamByName('TEXTBLOB').LoadFromStream(stream,ftMemo);
  69.     SQLQuery1.ExecSQL;
  70.     SQLTransaction1.Commit;
  71.     SQLQuery1.Close;
  72.   finally
  73.     stream.Free;
  74.   end;
  75. end;
  76.  

Assembler:
Code: Text  [Select]
  1. DB$_$TMASTERDATALINK_$__$$_CHECKBROWSEMODE
  2. 00000001001BA940 53                       push   %rbx
  3. 00000001001BA941 488d6424e0               lea    -0x20(%rsp),%rsp
  4. 00000001001BA946 4889cb                   mov    %rcx,%rbx
  5. 00000001001BA949 488b4b30                 mov    0x30(%rbx),%rcx
  6. 00000001001BA94D e87e33ffff               callq  0x1001adcd0 <DB$_$TDATASET_$__$$_GETACTIVE$$BOOLEAN>   //here it fails
  7. 00000001001BA952 84c0                     test   %al,%al
  8. 00000001001BA954 7409                     je     0x1001ba95f <DB$_$TMASTERDATALINK_$__$$_CHECKBROWSEMODE+31>
  9. 00000001001BA956 488b4b30                 mov    0x30(%rbx),%rcx
  10. 00000001001BA95A e8b142ffff               callq  0x1001aec10 <DB$_$TDATASET_$__$$_CHECKBROWSEMODE>
  11. 00000001001BA95F 90                       nop
  12.  

What I am doing wrong?
« Last Edit: September 17, 2019, 01:52:14 pm by minkob »
ASUS K53S i5
Fedora fc30.x86_64
Lazarus 2.0.2
FPC 3.0.4

minkob

  • New Member
  • *
  • Posts: 13
Re: [SOLVED]: RichMemo to/from Db
« Reply #1 on: September 17, 2019, 01:53:22 pm »
Done with Zeoslib.
ASUS K53S i5
Fedora fc30.x86_64
Lazarus 2.0.2
FPC 3.0.4