
30.08.2009, 17:19
|
 |
Гуру
|
|
Регистрация: 09.03.2009
Адрес: На курорте, из окна вижу теплое Баренцево море. Бррр.
Сообщения: 4,723
Репутация: 52347
|
|
Ну вот вам примерчик:
Код:
unit uPhotoDemo;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DB, DBClient, ExtDlgs, StdCtrls, Mask, DBCtrls, Grids, DBGrids;
type
TForm1 = class(TForm)
tblCustomer: TClientDataSet;
tblCustomerID: TAutoIncField;
tblCustomerFIO: TStringField;
tblCustomerPhoto: TBlobField;
DBGrid: TDBGrid;
edPicture: TDBImage;
edFIO: TDBEdit;
btnLoad: TButton;
dsCustomer: TDataSource;
OpenPictureDialog: TOpenPictureDialog;
procedure btnLoadClick(Sender: TObject);
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.btnLoadClick(Sender: TObject);
begin
if not OpenPictureDialog.Execute then Exit;
tblCustomer.Edit;
TBlobField(tblCustomer.FieldByName('Photo')).LoadFromFile(OpenPictureDialog.FileName);
tblCustomer.Post;
end;
end.
и DFM-файл
Код:
object Form1: TForm1
Left = 265
Top = 128
Width = 505
Height = 235
Caption = 'Form1'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'Tahoma'
Font.Style = []
OldCreateOrder = False
PixelsPerInch = 96
TextHeight = 13
object DBGrid: TDBGrid
Left = 8
Top = 32
Width = 337
Height = 161
DataSource = dsCustomer
TabOrder = 0
TitleFont.Charset = DEFAULT_CHARSET
TitleFont.Color = clWindowText
TitleFont.Height = -11
TitleFont.Name = 'Tahoma'
TitleFont.Style = []
Columns = <
item
Expanded = False
FieldName = 'ID'
Width = 26
Visible = True
end
item
Expanded = False
FieldName = 'FIO'
Width = 237
Visible = True
end
item
Expanded = False
FieldName = 'Photo'
Width = 55
Visible = True
end>
end
object edPicture: TDBImage
Left = 352
Top = 8
Width = 137
Height = 153
DataField = 'Photo'
DataSource = dsCustomer
Stretch = True
TabOrder = 1
end
object edFIO: TDBEdit
Left = 8
Top = 8
Width = 337
Height = 21
DataField = 'FIO'
DataSource = dsCustomer
TabOrder = 2
end
object btnLoad: TButton
Left = 376
Top = 168
Width = 97
Height = 25
Caption = 'Загрузить...'
TabOrder = 3
OnClick = btnLoadClick
end
object tblCustomer: TClientDataSet
Active = True
Aggregates = <>
Params = <>
Left = 200
Top = 56
Data = {
8B0000009619E0BD0100000018000000030000000000030000008B0002494404
0001000000010007535542545950450200490008004175746F696E6300034649
4F01004900000001000557494454480200020032000550686F746F04004B0000
000100075355425459504502004900070042696E6172790001000C4155544F49
4E4356414C55450400010001000000}
object tblCustomerID: TAutoIncField
FieldName = 'ID'
end
object tblCustomerFIO: TStringField
FieldName = 'FIO'
Size = 50
end
object tblCustomerPhoto: TBlobField
FieldName = 'Photo'
end
end
object dsCustomer: TDataSource
DataSet = tblCustomer
Left = 232
Top = 56
end
object OpenPictureDialog: TOpenPictureDialog
Left = 408
Top = 56
end
end
__________________
Жизнь такова какова она есть и больше никакова.
Помогаю за спасибо.
|