home *** CD-ROM | disk | FTP | other *** search
/ CD Actual Thematic 25: Programming / pc_actual_25.iso / Delphi / PolarDraw / data1.cab / Samples / Visual_Basic / BlobSample / Form1.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  2001-08-31  |  6.9 KB  |  212 lines

  1. VERSION 5.00
  2. Object = "{52DE3A21-0A3F-11D4-B9D2-008048FD54E6}#2.0#0"; "POLARDraw20.ocx"
  3. Object = "{67397AA1-7FB1-11D0-B148-00A0C922E820}#6.0#0"; "MSADODC.OCX"
  4. Begin VB.Form Form1 
  5.    BorderStyle     =   1  'Fixed Single
  6.    Caption         =   "BLOB Demo"
  7.    ClientHeight    =   7500
  8.    ClientLeft      =   45
  9.    ClientTop       =   330
  10.    ClientWidth     =   9930
  11.    LinkTopic       =   "Form1"
  12.    MaxButton       =   0   'False
  13.    MinButton       =   0   'False
  14.    ScaleHeight     =   7500
  15.    ScaleWidth      =   9930
  16.    StartUpPosition =   3  'Windows Default
  17.    Begin POLARDRAW20Lib.POLARDraw pd1 
  18.       Height          =   7335
  19.       Left            =   120
  20.       TabIndex        =   0
  21.       Top             =   120
  22.       Width           =   6375
  23.       _Version        =   131072
  24.       _ExtentX        =   11245
  25.       _ExtentY        =   12938
  26.       _StockProps     =   224
  27.       Appearance      =   1
  28.       PaperShadowColor=   0
  29.       EditMode        =   4
  30.       DrawPaperOutline=   -1  'True
  31.       DrawPaperShadow =   -1  'True
  32.       PaperShadowOffset=   23601932
  33.       ViewportOriginX =   1241728
  34.       ViewportOriginY =   24044568
  35.       PageOriginX     =   4385055
  36.       PageOriginY     =   2011714655
  37.       HorizontalGrid  =   567
  38.       VerticalGrid    =   567
  39.       SelectionCount  =   16
  40.       ShapeCount      =   1598273192
  41.       CanvasWidth     =   0
  42.       CanvasHeight    =   1598275386
  43.    End
  44.    Begin VB.TextBox Text2 
  45.       DataField       =   "Description"
  46.       DataSource      =   "Adodc1"
  47.       Height          =   285
  48.       Left            =   7200
  49.       TabIndex        =   4
  50.       Text            =   "Text2"
  51.       Top             =   1080
  52.       Width           =   2655
  53.    End
  54.    Begin VB.TextBox Text1 
  55.       DataField       =   "Name"
  56.       DataSource      =   "Adodc1"
  57.       Height          =   285
  58.       Left            =   7200
  59.       TabIndex        =   3
  60.       Text            =   "Text1"
  61.       Top             =   600
  62.       Width           =   2655
  63.    End
  64.    Begin VB.CommandButton btnStore 
  65.       Caption         =   "Store Picture"
  66.       Height          =   495
  67.       Left            =   6600
  68.       TabIndex        =   2
  69.       Top             =   6480
  70.       Width           =   3255
  71.    End
  72.    Begin MSAdodcLib.Adodc Adodc1 
  73.       Height          =   375
  74.       Left            =   6600
  75.       Top             =   7080
  76.       Width           =   3255
  77.       _ExtentX        =   5741
  78.       _ExtentY        =   661
  79.       ConnectMode     =   3
  80.       CursorLocation  =   3
  81.       IsolationLevel  =   -1
  82.       ConnectionTimeout=   15
  83.       CommandTimeout  =   30
  84.       CursorType      =   1
  85.       LockType        =   3
  86.       CommandType     =   2
  87.       CursorOptions   =   0
  88.       CacheSize       =   50
  89.       MaxRecords      =   0
  90.       BOFAction       =   0
  91.       EOFAction       =   0
  92.       ConnectStringType=   1
  93.       Appearance      =   1
  94.       BackColor       =   -2147483643
  95.       ForeColor       =   -2147483640
  96.       Orientation     =   0
  97.       Enabled         =   -1
  98.       Connect         =   "Provider=Microsoft.Jet.OLEDB.3.51;Persist Security Info=False;Data Source=demo.mdb;Mode=Read|Write"
  99.       OLEDBString     =   "Provider=Microsoft.Jet.OLEDB.3.51;Persist Security Info=False;Data Source=demo.mdb;Mode=Read|Write"
  100.       OLEDBFile       =   ""
  101.       DataSourceName  =   ""
  102.       OtherAttributes =   ""
  103.       UserName        =   ""
  104.       Password        =   ""
  105.       RecordSource    =   "PicTable"
  106.       Caption         =   "Pictures"
  107.       BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
  108.          Name            =   "MS Sans Serif"
  109.          Size            =   8.25
  110.          Charset         =   238
  111.          Weight          =   400
  112.          Underline       =   0   'False
  113.          Italic          =   0   'False
  114.          Strikethrough   =   0   'False
  115.       EndProperty
  116.       _Version        =   393216
  117.    End
  118.    Begin VB.Label Label4 
  119.       Caption         =   "Label4"
  120.       DataField       =   "ID"
  121.       DataSource      =   "Adodc1"
  122.       Height          =   255
  123.       Left            =   7200
  124.       TabIndex        =   7
  125.       Top             =   120
  126.       Width           =   2655
  127.    End
  128.    Begin VB.Label Label3 
  129.       Caption         =   "ID:"
  130.       Height          =   255
  131.       Left            =   6600
  132.       TabIndex        =   6
  133.       Top             =   120
  134.       Width           =   495
  135.    End
  136.    Begin VB.Label Label2 
  137.       Caption         =   "Desc:"
  138.       Height          =   255
  139.       Left            =   6600
  140.       TabIndex        =   5
  141.       Top             =   1080
  142.       Width           =   495
  143.    End
  144.    Begin VB.Label Label1 
  145.       Caption         =   "Name:"
  146.       Height          =   255
  147.       Left            =   6600
  148.       TabIndex        =   1
  149.       Top             =   600
  150.       Width           =   495
  151.    End
  152. Attribute VB_Name = "Form1"
  153. Attribute VB_GlobalNameSpace = False
  154. Attribute VB_Creatable = False
  155. Attribute VB_PredeclaredId = True
  156. Attribute VB_Exposed = False
  157. Dim WithEvents rs As Recordset
  158. Attribute rs.VB_VarHelpID = -1
  159. Private Declare Function GlobalLock Lib "kernel32" (ByVal hMem As Long) As Long
  160. Private Declare Function GlobalSize Lib "kernel32" (ByVal hMem As Long) As Long
  161. Private Declare Function GlobalUnlock Lib "kernel32" (ByVal hMem As Long) As Long
  162. Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
  163. Private Declare Function GlobalAlloc Lib "kernel32" (ByVal wFlags As Long, ByVal dwBytes As Long) As Long
  164. Private Declare Function GlobalFree Lib "kernel32" (ByVal hMem As Long) As Long
  165. Private Sub btnStore_Click()
  166.    WriteBlob
  167. End Sub
  168. Private Sub Form_Load()
  169.     Set rs = Adodc1.Recordset
  170.     rs.MoveFirst
  171.     pd1.ActiveWindow.FitTo polFitToPage
  172. End Sub
  173. Private Sub rs_MoveComplete(ByVal adReason As ADODB.EventReasonEnum, ByVal pError As ADODB.Error, adStatus As ADODB.EventStatusEnum, ByVal pRecordset As ADODB.Recordset)
  174.     If pRecordset.BOF Or pRecordset.EOF Then
  175.         Exit Sub
  176.     End If
  177.     ReadBlob
  178. End Sub
  179. Private Sub WriteBlob()
  180.    Dim h As OLE_HANDLE
  181.    pd1.WriteToBlob h, 0
  182.    Dim data() As Byte
  183.    Dim lBuff As Long
  184.    Dim lSize As Long
  185.    lSize = GlobalSize(h)
  186.    lBuff = GlobalLock(h)
  187.    ReDim data(lSize)
  188.    CopyMemory data(0), ByVal lBuff, lSize
  189.    lBuff = GlobalUnlock(h)
  190.    rs.Fields("Picture").AppendChunk (data)
  191.    GlobalFree (h)
  192.    rs.Update
  193. End Sub
  194. Private Sub ReadBlob()
  195.     Dim data() As Byte
  196.     lSize = rs.Fields("Picture").ActualSize
  197.     If lSize = 0 Then
  198.         pd1.ActivePage.Shapes.Delete
  199.         Exit Sub
  200.     End If
  201.     ReDim data(lSize)
  202.     Dim h As Long
  203.     Dim lBuff As Long
  204.     h = GlobalAlloc(0, lSize)
  205.     lBuff = GlobalLock(h)
  206.     data = rs.Fields("Picture").GetChunk(lSize)
  207.     CopyMemory ByVal lBuff, data(0), lSize
  208.     GlobalUnlock (h)
  209.     pd1.ReadFromBlob h, lSize
  210.     GlobalFree (h)
  211. End Sub
  212.