这段代码绝对可以:(trim函数把最后的一个符号去掉就可以显示出来了)
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ExtCtrls, DBCtrls, Grids, DBGrids, Db, DBTables;
type
TForm1 = class(TForm)
DataSource1: TDataSource;
Table1: TTable;
DBGrid1: TDBGrid;
DBNavigator1: TDBNavigator;
Table1SpeciesNo: TFloatField;
Table1Category: TStringField;
Table1Common_Name: TStringField;
Table1SpeciesName: TStringField;
Table1Lengthcm: TFloatField;
Table1Length_In: TFloatField;
Table1Notes: TMemoField;
Table1Graphic: TGraphicField;
procedure DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
procedure Table1NotesGetText(Sender: TField; var Text: String;
DisplayText: Boolean);
procedure Table1NotesSetText(Sender: TField; const Text: String);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
var
bmp:Tbitmap;
Outrect:Trect;
Bmpwidth:integer;
begin
Outrect:=rect;
if column.field=Table1Common_name then
begin //ok
Bmp:=Tbitmap.create;
try
Bmp.assign(Table1Graphic);
bmpWidth:=(Rect.bottom-Rect.top)*2;
Outrect.Right:=rect.left+BmpWidth;
dbGrid1.canvas.StretchDraw(outRect,Bmp);
finally
bmp.free;
end; //try
outrect:=rect;
Outrect.left:= Outrect.left+BmpWidth;
end; //ok
//color
if (column.field=Table1Lengthcm) and (Table1Lengthcm.AsInteger>100) then
Dbgrid1.canvas.font.Color:=clred;
Dbgrid1.defaultdrawdatacell(outrect,column.field,state);
end;
procedure TForm1.Table1NotesGetText(Sender: TField; var Text: String;
DisplayText: Boolean);
begin
text:=trim(sender.asString);
end;
procedure TForm1.Table1NotesSetText(Sender: TField; const Text: String);
begin
sender.AsString:=text;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
end;
end.