Populating Graphic and Memo Fields

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.
OgunboAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ZifNabCommented:
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
ZifNabCommented:
If this isn't what you need, please specify.
Regards, Zif.
0
tomerleiCommented:
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
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

ZifNabCommented:
Hey tomerlei,

Why do send my comments as an answer?

Regards, Zif.
0
ZifNabCommented:
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
OgunboAuthor Commented:
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
ZifNabCommented:
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
OgunboAuthor Commented:
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
ZifNabCommented:
???? 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
OgunboAuthor Commented:
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
ZifNabCommented:
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
OgunboAuthor Commented:
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
ZifNabCommented:
On which Delphi version are you working?
0
OgunboAuthor Commented:
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
ZifNabCommented:
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
OgunboAuthor Commented:
The answer to this question is reserved exclusively for Zifnab.  Thanks.
0
ZifNabCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
OgunboAuthor Commented:
Thank you Zif for your patience.
0
ZifNabCommented:
Hi Ogunbo, no problem, glad I could help you.

Happy programming,

May the source be with you.
Regards, Zif.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.