test

progging - To wander about and beg; to seek food or other supplies by low arts; to seek for advantage by mean shift or tricks.
progging - Programmer slang for writing computer code.
Viser innlegg med etiketten paradox. Vis alle innlegg
Viser innlegg med etiketten paradox. Vis alle innlegg

fredag 5. august 2011

Dynamically adding a GRAPHIC field to an existing Paradox table

I wanted to add a few new fields to an existing Paradox database table. We already had a method for adding new fields. This is using SQL to add new fields kinda like:

'ALTER TABLE ' + TableName + ' ADD COLUMN ' + Field + ' ' + FieldType

so the FieldType is a string and one of that parameters. So I thought GRAPHIC would be a valid type. But no, it complains with the message "Capability not supported":



According to Embarcadero:
"This error is returned by the BDE when the BDE parses an SQL string to be sent to a server and the syntax of the string is not supported by the BDE"
So, as of now I still don't have a solution to this problem.

NOTE: Using BLOB as FieldName works just fine (but testing this caused other problems...)

EDIT: 2011-08-25
Using MEMO as the type gave the same error. Using BLOB works and actually creates a MEMO field! :)

Only workaround found was to delete the table and create a new one using Delphi TTable class and field type ftGraphic - FieldDefs.Add('Icon', ftGraphic, 0, False);

Useful link for simple SQL coding:
http://www.thedbcommunity.com/index.php?option=com_content&task=view&id=138&Itemid=46
This also mentions under "Unsupported Capabilities" that "There are a number of table modifications which cannot be performed using Local SQL, such as foreign key constraints, range limitations, picture settings, etc."

Getting an Image into QuickReport


I had a big problem getting a .bmp file to show up in a QReport. Everything seemed straight forward. I had to do this dynamically during run-time, so I would read in the image to a paradox database and then have the QReport point to the correct database field.

The problem was that when I first configured the QReport, the database field was MEMO and not GRAPHIC. This information is stored in the .QR2 report file. And even though I corrected this field in the database using Database Manager, it would not be updated in the QuickReport.

The solution was to remove the dataset and add it again. This time the field correctly showed up as GRAPHIC, and the image showed up beautifully :-)

One possible solution could be to only remove the field in the dataset and then add it again.

The initial code for getting in image into the DB was:


(FieldByName('Icon') as TGraphicField).LoadFromFile('\path\to\image.bmp');

Although this works fine, the image file has to be available on the disk when the program runs. A better solution is to get the images included in the .exe as an embedded resource. The simplest way to achieve this was to include a TImageList on a form, and populate this with the images I needed. Then use the following code to put them in the database:


procedure InsertImageToDB(Field: TField; ImageIndex: Integer);
var
  stream: TStream;
  bmp: TBitmap;
begin
  bmp := TBitmap.Create();
  stream := Field.DataSet.CreateBlobStream(Field, bmWrite);
  try
    Frm.ImageList.GetBitmap(ImageIndex, bmp);
    bmp.SaveToStream(stream);
  finally
    stream.Free;
    bmp.Free;
  end;
end;
This has to be included in a Edit()...Post() block to get it posted to the DB.