?
Solved

Populating Graphic and Memo Fields

Posted on 1998-02-12
19
Medium Priority
?
381 Views
Last Modified: 2010-04-04
I have a table with several fields including a graphic and memo fields.  I am having trouble in populating these two field with pictures and data.  I will like to have a complete source as to how to do it.  I have tried loading in the graphics one at a time using LoadFromFile but I am unable to load more than one.  Will appreciate any help.
0
Comment
Question by:Ogunbo
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 11
  • 7
19 Comments
 
LVL 8

Expert Comment

by:ZifNab
ID: 1359090
There are a number of ways to load a bitmap image into the BLOB field of a dBASE
1) copying the data from the Windows clipboard into a TDBImage component connect
2) using the LoadFromFile method of the TBLOBField component,
3) using the Assign method to copy an object of type TBitmap into the Picture pr

The first method, copying the bitmap from the clipboard, is probably most handy
 when an application needs to add bitmaps to a table when the enduser is running
g the application. A TDBImage component is used to act as an interface between t
table.

Because the Windows clipboard can contain data in formats othher than just bitma
ap, it is advisable to check the format prior to calling the CopyFromClipboard m
method. To do this, a TClipboard object is created and its HasFormat method is u

Here is an example showing the contents of the clipboard being copied into a TDB

  procedure TForm1.Button1Click(Sender: TObject);
  var
    C: TClipboard;
  begin
    C := TClipboard.Create;
    try
      if Clipboard.HasFormat(CF_BITMAP) then
        DBImage1.PasteFromClipboard
      else
        ShowMessage('Clipboard does not contain a bitmap!');
    finally
      C.Free;
    end;
  end;

The second method of filling a BLOB field with a bitmap involves loading the bit
tmap directly from a file on disk into the BLOB field. This method lends itself
 equally well to uses at run-time for the end-user as for the developer building

This method uses the LoadFromFile method of the TBLOBField component, the Delphi
i representation of a dBASE for Windows Binary field or a Paradox for Windows Gr

The LoadFromFile method of the TBLOBField component requires a single parameter:
: the name of the bitmap file to load, which is of type String. The value for th
his parameter may come from a number of sources from the enduser manually keying

Here is an example showing the use of the LoadFromFile method for a TBLOBField c
component named Table1Bitmap (a field called Bitmap in the table associated with

  procedure TForm1.Button2Clicck(Sender: TObject);
  begin
    Table1Bitmap.LoadFromFile(
      'c:\delphi\images\splash\16color\construc.bmp');
  end;

The third method uses the Assign method to copy the contents of an object of typ
pe TBitmap into the Picture property of a TDBImage component. An object of type
 TBitmap might be the Bitmap property of the Picture object property of a TImage

Here is an example using the Assign method. In this case, a stand-alone TBitmap
 object is used. To put a bitmap image into the TBitmap, the LoadFromFile method

  procedure TForm1.Button3Click(Sender: TObject);
  var
    B: TBitmap;
  begin
    B := TBitmap.Create;
    try
      B.LoadFromFile('c:\delphi\images\splashh\16color\athena.bmp');
      DBImage1.Picture.Assign(B);
    finally
      B.Free;
    end;
  end;

If you define a TMemoField component for a memo field, the data is
automatically available through that TMemoField component and you should
not need to manually copy the data from the memo field to the TMemoField.

But if all you are trying to do is copy memo data to a null-terminated
string buffer in memory (with or without a TMemoField component defined),
try using the TBlobStream object, designed just for this purpose. For
example, copying the data from a Paradox memo field to a TMemo component:

  procedure TForm1.Button1Click(Sender: TObject);
  var
    P: PChar;
    S: Integer;
    BS: TBlobStream;
  begin
    BS := TBlobStream.Create(TMemoField(Table1.Fields[1]), bmRead);
    try
      S := 32000;
      P := AllocMem(S);
      FillChar(P^, S, #0);
      BS.Read(P^, S);
      Memo1.SetTextBuf(P);
    finally
      BS.Free;
      FreeMem(P, S);
    end;
  end;
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1359091
If this isn't what you need, please specify.
Regards, Zif.
0
 
LVL 4

Expert Comment

by:tomerlei
ID: 1359092
There are a number of ways to load a bitmap image into the BLOB field of a dBASE
                  1) copying the data from the Windows clipboard into a TDBImage component
                  connect
                  2) using the LoadFromFile method of the TBLOBField component,
                  3) using the Assign method to copy an object of type TBitmap into the Picture pr

                  The first method, copying the bitmap from the clipboard, is probably most handy
                   when an application needs to add bitmaps to a table when the enduser is running
                  g the application. A TDBImage component is used to act as an interface between t
                  table.

                  Because the Windows clipboard can contain data in formats othher than just bitma
                  ap, it is advisable to check the format prior to calling the CopyFromClipboard m
                  method. To do this, a TClipboard object is created and its HasFormat method is u

                  Here is an example showing the contents of the clipboard being copied into a TDB

                    procedure TForm1.Button1Click(Sender: TObject);
                    var
                      C: TClipboard;
                    begin
                      C := TClipboard.Create;
                      try
                      if Clipboard.HasFormat(CF_BITMAP) then
                      DBImage1.PasteFromClipboard
                      else
                      ShowMessage('Clipboard does not contain a bitmap!');
                      finally
                      C.Free;
                      end;
                    end;

                  The second method of filling a BLOB field with a bitmap involves loading the bit
                  tmap directly from a file on disk into the BLOB field. This method lends itself
                   equally well to uses at run-time for the end-user as for the developer building

                  This method uses the LoadFromFile method of the TBLOBField component, the
                  Delphi
                  i representation of a dBASE for Windows Binary field or a Paradox for Windows Gr


                  The LoadFromFile method of the TBLOBField component requires a single
                  parameter:
                  : the name of the bitmap file to load, which is of type String. The value for th
                  his parameter may come from a number of sources from the enduser manually
                  keying

                  Here is an example showing the use of the LoadFromFile method for a TBLOBField
                  c
                  component named Table1Bitmap (a field called Bitmap in the table associated with

                    procedure TForm1.Button2Clicck(Sender: TObject);
                    begin
                      Table1Bitmap.LoadFromFile(
                      'c:\delphi\images\splash\16color\construc.bmp');
                    end;

                  The third method uses the Assign method to copy the contents of an object of typ
                  pe TBitmap into the Picture property of a TDBImage component. An object of type
                   TBitmap might be the Bitmap property of the Picture object property of a TImage

                  Here is an example using the Assign method. In this case, a stand-alone TBitmap
                   object is used. To put a bitmap image into the TBitmap, the LoadFromFile method

                    procedure TForm1.Button3Click(Sender: TObject);
                    var
                      B: TBitmap;
                    begin
                      B := TBitmap.Create;
                      try
                      B.LoadFromFile('c:\delphi\images\splashh\16color\athena.bmp');
                      DBImage1.Picture.Assign(B);
                      finally
                      B.Free;
                      end;
                    end;

                  If you define a TMemoField component for a memo field, the data is
                  automatically available through that TMemoField component and you should
                  not need to manually copy the data from the memo field to the TMemoField.

                  But if all you are trying to do is copy memo data to a null-terminated
                  string buffer in memory (with or without a TMemoField component defined),
                  try using the TBlobStream object, designed just for this purpose. For
                  example, copying the data from a Paradox memo field to a TMemo component:

                    procedure TForm1.Button1Click(Sender: TObject);
                    var
                      P: PChar;
                      S: Integer;
                      BS: TBlobStream;
                    begin
                      BS := TBlobStream.Create(TMemoField(Table1.Fields[1]), bmRead);
                      try
                      S := 32000;
                      P := AllocMem(S);
                      FillChar(P^, S, #0);
                      BS.Read(P^, S);
                      Memo1.SetTextBuf(P);
                      finally
                      BS.Free;
                      FreeMem(P, S);
                      end;
                    end;
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 8

Expert Comment

by:ZifNab
ID: 1359093
Hey tomerlei,

Why do send my comments as an answer?

Regards, Zif.
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1359094
HEY TOMERLEI, I CAN UNDERSTAND THAT YOU PROPOSE AN ANSWER WHEN SOMEBODY HAS GIVEN A COMMENT, BUT TO GIVE AN ANSWER JUST THE SAME AS THE COMMENT. SORRY, THAT I REALLY DON'T UNDERSTAND! ESPECIALLY IF YOU DON't GIVE A REACTION ON MY QUESTION.
NOW, it will be interesting to see if it's what Ogunbo needs.
0
 

Author Comment

by:Ogunbo
ID: 1359095
Thank you Zif and tomerlei for your prompt attention to my request.  It looks however, that tomerlei will have the points for this question.  I have come across this information which was produced by Steve Koterski for another novice like me at the developers.href.com.  At the time I tried all of the three approaches and they did not work.  For the first suugested approach, I got the message 'Error undeclared identifier TClipboard" and also for clipboard.  When I tried the second, the program compiled but as soon as I click the button, I see an access violation error.  As for the third approach, the program compiled and the button works by retrieving a picture into the DBImage.  But If I tried to use the DBnavigator to advance to another record, I get an error message.
I have more than one record and the first approach would have been good provided I can link the DBImage to the DBNavigator such that after one field has been populated, I can go to another record, paste another picture and advance to another record until all records have been populated with bitmaps.  So if you have any sugestion, I'd appreciate it.  On my form I'd love to have a dbgrid, a Tdataset, a TTable, a navigator button, a dbmemo, a dbimage, and a button with all linked together. I'd love to click the button paste a bitmap, navigate to another record, click button, paste, and navigate to another etc.
Thank you for all your help.  I will increase the points to 100 if need be.  
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1359096
Well Ogunbo, I'm sorry to hear that somebody gets the points with an answer just as the comment before. I don't get it anymore? I give a comment. Tomerlei, cuts? and paste this comment as an answer and gets the points. Sorry, but this is really.....

c.u.
0
 

Author Comment

by:Ogunbo
ID: 1359097
hey Zif, don't get me wrong.  Actually both of your answer and taht of Tomerlei's got to me at the same time.  However, I believe tomerlei gave the last answer and it's his name that the computer recognizes, and this is why under the grading option, tomerlei's name is there.  This may be a problem with the design of the program, sorry. Thank you though for your answer and please come to my aid again if need be.
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1359098
???? Nope can't be, I first give a comment (no answer!!!) After a few minutes (10-15 could be longer, don't know anymore)I got a mail about that your mail was answered. I looked at the answer and by holy it's just the same as mine. Very strange...
But heck, I don't mind I don't do it for the points, but it really pisses me of if soembody earns points this way. By the the reject option still works.
I'll still help you

0
 

Author Comment

by:Ogunbo
ID: 1359099
Zifnab,I haven't heard back from tormelei since he posted a response to my question.  If you think you can help, please do and I'll make sure that you get the points.  I have written some additional comments prior to this on my failure to accomplish the problem using your suggestion.  The comments are reproduced here.
"For the first suugested approach, I got the message 'Error undeclared identifier TClipboard" and also for clipboard. When I tried the second, the program compiled but as soon as I click the button, I see an access violation error. As for the third approach, the program compiled and the button works by retrieving a picture into the DBImage. But If I tried to use the DBnavigator to advance to another record, I get an error message. I have more than one record and the first approach would have been good provided I can link the DBImage to the DBNavigator such that after one field has been populated, I can go to another record, paste another picture and advance to another record until all records have been populated with bitmaps. So if you have any sugestion,I'd appreciate it. On my form I'd love to have a dbgrid, a Tdataset, a TTable, a navigator button, a dbmemo, a
dbimage, and a button with all linked together. I'd love to click the button paste a bitmap, navigate to another record, click button, paste, and navigate to another etc.
Thank you for all your help. I will increase the points to 100 if need be".
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1359100
Suggestions :

 1. You've to add Clipbrd to the use clausule.
 2,3. Have you changed the this directory 'c:\delphi\images\splashh\16color\athena.bmp', to the correct directory (or just a path to an .bmp?)

Waiting for a  comment.
0
 

Author Comment

by:Ogunbo
ID: 1359101
Hi Zifnab,
I included clipboard in the uses list and the project did not compile.  The error message says "File not found, clipboard.dcu".
For 2,3 I am just using a path to the bmp (e.g C:\pictures\pic1.bmp).
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1359102
On which Delphi version are you working?
0
 

Author Comment

by:Ogunbo
ID: 1359103
Hi Zifnab,
I am using D3 but I,ve been able to get it to work.  I was spelling the "clipbrd" as clipboard in the uses list.  So this was the problem all along.  

Thank you for your help and patience.  I'd like to increase the points to 75.  Do you have an idea how to send this points to you instead of tomerlei?  If not, I can just reopen the question and you can try to paste your answers from here to there so that the computer will request me to grade your answer.

Waiting to hear from you.

0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1359104
Hi ogundo,

Is it working?

If you want to grade me, you do the following :

When you give comments, you can grade the answer (if your question is aswered, like in this case) : You can do this by giving points or you can reject the answer (reject = saying answer is not sufficient and another person can answer the question). So what you have to do is choosing 'reject', with a comment if you like. The question is back online, so all experts can answer the question.

Then I can answer the question and you can grade my answer.

PS. You don't have to increase the points! Thats really not necessary.

Regards,
Zif.
0
 

Author Comment

by:Ogunbo
ID: 1359105
The answer to this question is reserved exclusively for Zifnab.  Thanks.
0
 
LVL 8

Accepted Solution

by:
ZifNab earned 280 total points
ID: 1359106
Hi Ogundo,

Here is the answer taken by Ogunbo. For more possible solutions, read the comments thread.

Add Clipbrd to the uses clausule, before you try out this code :

Here is an example showing the contents of the clipboard being copied into a TDB

                      procedure TForm1.Button1Click(Sender: TObject);
                      var
                      C: TClipboard;
                      begin
                      C := TClipboard.Create;
                      try
                      if Clipboard.HasFormat(CF_BITMAP) then
                      DBImage1.PasteFromClipboard
                      else
                      ShowMessage('Clipboard does not contain a bitmap!');
                      finally
                      C.Free;
                      end;
                      end;

Hope you're solution is solved. If not, just ask!

Regards,
Zif.
0
 

Author Comment

by:Ogunbo
ID: 1359107
Thank you Zif for your patience.
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1359108
Hi Ogunbo, no problem, glad I could help you.

Happy programming,

May the source be with you.
Regards, Zif.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question