Recent

Author Topic: Is there any effort by core developers to enable DBgrid to show Memo fields?  (Read 11726 times)

snorkel

  • Hero Member
  • *****
  • Posts: 817
Just wondering if there was any effort to enhance the DBGrid to automatically show and edit memo fields instead of
show [memo]

This is one of the biggest annoyances of using the DGbrid in Delphi and it would be super nice to have the Lazarus DBgrid out do the Delphi one
in yet another way.

If not maybe we could add this to the Grids reference page:

http://lazarus.freepascal.org/index.php/topic,16300.0.html
***Snorkel***
If I forget, I always use the latest stable 32bit version of Lazarus and FPC. At the time of this signature that is Laz 3.0RC2 and FPC 3.2.2
OS: Windows 10 64 bit

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Go ahead, be my guest and add that info to the grids reference page ;)

AFAIK, there is no effort to show the contents of memo fields... but you could always raise a bug report in the issue tracker.
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

teos

  • Full Member
  • ***
  • Posts: 157
automatically showing memo fields in a DBgrid IMHO is not implemented because of a fairly simple reason: speed.

showing memo fields with large content would slow down fetching/showing data dramatically.

Dibo

  • Hero Member
  • *****
  • Posts: 1048
I think this is good that [MEMO] is showing, programmer know that he must decide what to do with this kind of field. Especially when there is easy way to handle it. If you are sure that string is not to big to have affect on efficient, you can just add field event OnGetText:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.OnGetMemoText(Sender: TField; var aText: string;
  2.   DisplayText: Boolean);
  3. begin
  4.   if DisplayText then
  5.     aText := Sender.AsString;
  6. end;

I'm not sure but second reason is that some of databases (TSQLQuery is wrapper for postgres, sqlite, mysql etc) can store binary data in TEXT fields, so [MEMO] doesn't mean that there is a big text only.

But I'm wondering about Size field property. It has affect on VARCHAR field types, but it could also on MEMO fields. Why if size if <> 0 then [MEMO] is still showing?

u2o

  • Jr. Member
  • **
  • Posts: 72
  • No message
Hi all!

I´m working on a runtime menu, loading items and their icons from a sqlite3 db. I save the icons (png format) on a blob field
After, in the code load each icon with TMemoryStream -> TPortableNetworkGraphic -> TImageList.

Maybe it's posible... insert TPicture controls on the Grid rows to show images...

u2o

  • Jr. Member
  • **
  • Posts: 72
  • No message
and the db fields

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Please open a new thread when asking about a new subject.

Also please always specify your Lazarus, FPC, OS version. See link in signature below.
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11450
  • FPC developer.
I think this is good that [MEMO] is showing, programmer know that he must decide what to do with this kind of field. Especially when there is easy way to handle it. If you are sure that string is not to big to have affect on efficient, you can just add field event OnGetText:

Usually I only copy the first line of the  memo filed in the grid. Otherwise you get funny characters for the crlf pairs. I've put the method in the same datamodule as the connection, and a short procedure that walks the form tree and sets it to all twidememofields.

(Disclaimer: the above is Zeos, not sqldb experience)
 

u2o

  • Jr. Member
  • **
  • Posts: 72
  • No message
Why if size if <> 0 then [MEMO] is still showing?

If you use a TMemoryStream to load the Memo field, you can use:

Code: [Select]
var
  ms : TMemoryStream
  blobF : TBlobField;

Begin
  ms := TMemoryStream.Create;
  blobF := TBlobField( SQLQueryA.FieldByName('icon') );

  blobF.SaveToStream(ms);

  If (ms.Size > 0) then begin           // The MemoryStream has data
    // your code for this condition
  end;
end;


BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
@u2o: I see no code interacting with a grid there. How would the contents of the memory stream be displayed on the grid?
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

u2o

  • Jr. Member
  • **
  • Posts: 72
  • No message
@u2o: I see no code interacting with a grid there. How would the contents of the memory stream be displayed on the grid?

Yes, I use arrays to load the data in a TreeView, or in a menu. I haven't yet tested directly in the DBGrid. But is interesting, the ways that can be found to implement this code.
I started programming with Bash in Linux and Batch on Win. Then I move to VB6, and today I'm with Lazarus and the versatility that i found is awesome!

snorkel

  • Hero Member
  • *****
  • Posts: 817
automatically showing memo fields in a DBgrid IMHO is not implemented because of a fairly simple reason: speed.

showing memo fields with large content would slow down fetching/showing data dramatically.

I don't think that's the reason, you can have pretty large varchars and they work fine.
plus, you can use beginupdate/endupdate so the UI does not update while the grid loads.

Seems like it's just a carry over from the delphi dbgrid.
***Snorkel***
If I forget, I always use the latest stable 32bit version of Lazarus and FPC. At the time of this signature that is Laz 3.0RC2 and FPC 3.2.2
OS: Windows 10 64 bit

snorkel

  • Hero Member
  • *****
  • Posts: 817
why couldn't there just be a option to show memo fields?  That way users with speed issues would not have to use
it? 
***Snorkel***
If I forget, I always use the latest stable 32bit version of Lazarus and FPC. At the time of this signature that is Laz 3.0RC2 and FPC 3.2.2
OS: Windows 10 64 bit

taazz

  • Hero Member
  • *****
  • Posts: 5368
The memo field can hold various type of data including html, rtf, and other formated text. Since the DBGrid has no text formating abilities it would unwise to allow something to show that makes no sense to the end user by default. That is why you have to make a conscious decision to show data on a dbgrid. It is better that way, making sure that you have full control over the result instead of getting unwanted results.
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

snorkel

  • Hero Member
  • *****
  • Posts: 817
The memo field can hold various type of data including html, rtf, and other formated text. Since the DBGrid has no text formating abilities it would unwise to allow something to show that makes no sense to the end user by default. That is why you have to make a conscious decision to show data on a dbgrid. It is better that way, making sure that you have full control over the result instead of getting unwanted results.

So can a varchar, I don't see the difference except that a memo can be of unlimited size.
Most databases have a separate blob type for handling data other than text and they have a type for for big text, i.e. PostreSQL has the text type.
In most RDBMS the text type at it's base is a blob, but a blob meant for storing text.

So I really disagree with the whole [MEMO] thing and think the DBgrid should handle it in a better way, The Lazarus DBgrid is already considerably better than the Delphi DBgrid, so why
keep the [MEMO] behavior from the stock delphi DBgrid?  The lazarus DBgrid shows booleans as checkboxes automaticly, why not [MEMO]

Just my opinion on the matter.

Later,

Snorkel
***Snorkel***
If I forget, I always use the latest stable 32bit version of Lazarus and FPC. At the time of this signature that is Laz 3.0RC2 and FPC 3.2.2
OS: Windows 10 64 bit

 

TinyPortal © 2005-2018