Recent

Author Topic: DBGrid: crypt field side client  (Read 1451 times)

xinyiman

  • Hero Member
  • *****
  • Posts: 2256
    • Lazarus and Free Pascal italian community
DBGrid: crypt field side client
« on: April 19, 2018, 12:48:30 pm »
Hi guys, a question. I have a dbgrid that displays 3 fields

field1, field2, field3

I want to encrypt the field2 (it does not matter the algorithm, now I'm interested in the procedure). How do I display plain data in column2, but save the data in the database in an encrypted way? This only for field 2 is clear.
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

balazsszekely

  • Guest
Re: DBGrid: crypt field side client
« Reply #1 on: April 19, 2018, 12:55:46 pm »
Double click the query, select Field2 then go to OI and create the OnGetText event, then:
Code: Pascal  [Select][+][-]
  1. procedure TfMain.SQLQueryGetText(Sender: TField; var aText: string;
  2.   DisplayText: Boolean);
  3. begin
  4.   aText := Decrypt(Sender.AsString);
  5. end;
  6.  

Where Decrypt is your custom algorithm.

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: DBGrid: crypt field side client
« Reply #2 on: April 19, 2018, 12:56:26 pm »
you go to the field, you write an onGetText event where you decrypt the string and onSetText event where you encrypt it.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

 

TinyPortal © 2005-2018