initial commit
[rofl0r-KOL.git] / controls / sqlite / sqlite_demo / UnitX.pas
blob63d61173cedd46fa5235c4878bfc4d8d85bb165d
1 { KOL MCK } // Do not remove this line!
2 {$DEFINE KOL_MCK}
3 unit UnitX;
5 interface
7 {$IFDEF KOL_MCK}
8 uses Windows, Messages, ShellAPI, KOL, KOLSQLiteDb {$IFNDEF KOL_MCK}, mirror, Classes,
9 mckKOLSQLiteDb, mckCtrls, Controls, mckObjs {$ENDIF};
10 {$ELSE}
11 {$I uses.inc}
12 Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;
13 {$ENDIF}
15 type
16 {$IFDEF KOL_MCK}
17 {$I MCKfakeClasses.inc}
18 PForm1 = ^TForm1;
19 TForm1 = object(TObj)
20 Form: PControl;
21 {$ELSE not_KOL_MCK}
22 TForm1 = class(TForm)
23 {$ENDIF KOL_MCK}
24 KOLProject1: TKOLProject;
25 KOLApplet1: TKOLApplet;
26 KOLForm1: TKOLForm;
27 SLData: TKOLSLDataSource;
28 SLSession: TKOLSLSession;
29 SLQuery: TKOLSLQuery;
30 LVData: TKOLListView;
31 Label1: TKOLLabel;
32 Button1: TKOLButton;
33 SQLMemo: TKOLMemo;
34 Button2: TKOLButton;
35 procedure Button1Click(Sender: PObj);
36 procedure KOLForm1FormCreate(Sender: PObj);
37 procedure Button2Click(Sender: PObj);
38 procedure LVDataLVData(Sender: PControl; Idx, SubItem: Integer;
39 var Txt: String; var ImgIdx: Integer; var State: Cardinal;
40 var Store: Boolean);
41 procedure SLDataBusy(Sender: PObj; ObjectName: String;
42 BusyCount: Integer; var Cancel: Boolean);
43 procedure LVDataColumnClick(Sender: PControl; Idx: Integer);
44 private
45 procedure FillList(List : PControl);
46 { Private declarations }
47 public
48 { Public declarations }
49 end;
51 var
52 Form1 {$IFDEF KOL_MCK} : PForm1 {$ELSE} : TForm1 {$ENDIF} ;
54 {$IFDEF KOL_MCK}
55 procedure NewForm1( var Result: PForm1; AParent: PControl );
56 {$ENDIF}
58 implementation
60 {$IFNDEF KOL_MCK} {$R *.DFM} {$ENDIF}
62 {$IFDEF KOL_MCK}
63 {$I UnitX_1.inc}
64 {$ENDIF}
66 procedure TForm1.FillList(List : PControl);
67 var
68 i : Integer;
69 begin
70 List.BeginUpdate;
71 try
72 while List.LVColCount > 0 do List.LVColDelete(0);
73 for i:=0 to SLQuery.ColCount-1 do List.LVColAdd(SLQuery.ColName[i],taLeft,55);
74 List.LVCount := SLQuery.RowCount;
75 for i:=0 to LVData.LVColCount-1 do SendMessage(LVData.Handle,LVM_SETCOLUMNWIDTH,i,Integer(LVSCW_AUTOSIZE));
76 finally
77 List.EndUpdate;
78 end;
79 end;
81 procedure TForm1.Button1Click(Sender: PObj);
82 begin
83 Form.Close;
84 end;
86 procedure TForm1.KOLForm1FormCreate(Sender: PObj);
87 begin
88 if SLData.Initialized then
89 Label1.Caption := Format('Library SQLite version: %s, encoding : %s',[SLData.Version,SLData.Encoding])
90 else
91 Label1.Caption := 'Database engine not initialized';
92 end;
98 procedure TForm1.LVDataLVData(Sender: PControl; Idx, SubItem: Integer;
99 var Txt: String; var ImgIdx: Integer; var State: Cardinal;
100 var Store: Boolean);
101 begin
102 Store := false;
103 ImgIdx := -1;
104 SLQuery.CurIndex := Idx;
105 Txt := SLQuery.SField[SubItem];
106 end;
108 procedure TForm1.SLDataBusy(Sender: PObj; ObjectName: String;
109 BusyCount: Integer; var Cancel: Boolean);
110 begin
111 Label1.Caption := Format('Database is locked (%d)',[BusyCount]);
112 if BusyCount > 3 then Cancel := true;
113 end;
117 procedure TForm1.Button2Click(Sender: PObj);
118 begin
119 with SLSession^,SLQuery^ do begin
120 Close;
121 StartTransaction;
122 SQL.Text := SQLMemo.Text;
123 if Open([]) > 0 then begin
124 Rollback;
125 MsgBox(ErrorMessage,mb_iconexclamation);
127 else
128 Commit;
129 First;
130 Label1.Caption := Format('RowCount=%d ,RowsAffected=%d, ColCount=%d, RowID=%d, CurIndex=%d',[RowCount,RowsAffected,ColCount,RowID,CurIndex]);
131 FillList(LVData);
132 end;
133 end;
135 procedure TForm1.LVDataColumnClick(Sender: PControl; Idx: Integer);
136 begin
137 SendMessage(LVData.Handle,LVM_SETCOLUMNWIDTH,IDx,Integer(LVSCW_AUTOSIZE));
138 end;
140 end.