-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtablesdirectoryfrm.pas
114 lines (93 loc) · 2.96 KB
/
tablesdirectoryfrm.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
unit TablesDirectoryFrm;
{$mode ObjFPC}{$H+}
interface
uses
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, DBCtrls, StdCtrls,
DBUnit, LCLType, MainFrm, DB;
type
{ TTablesDirectoryForm }
TTablesDirectoryForm = class(TForm)
ColumnsList: TDBLookupListBox;
ColumnsListLbl: TLabel;
DBText1: TDBText;
SearchEdit: TEdit;
ShortcutLbl: TLabel;
TableList: TDBLookupListBox;
TablesListLbl: TLabel;
procedure ColumnsListKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure FormShow(Sender: TObject);
procedure SearchEditChange(Sender: TObject);
procedure TableListClick(Sender: TObject);
procedure TableListKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
private
procedure AddTextToMainFormScriptSQLEdit(const TextToAdd: string);
public
TargetEdit: TMemo;
end;
var
TablesDirectoryForm: TTablesDirectoryForm;
implementation
uses DataFrm;
{$R *.lfm}
{ TTablesDirectoryForm }
procedure TTablesDirectoryForm.FormShow(Sender: TObject);
begin
if (Dataform.FromConnection.Connected = False) and (Dataform.FromMySQL80Connection.Connected = False) then
begin
showmessage('Connect to SQL server first!');
TablesDirectoryForm.Close;
end;
if (Dataform.TablesQuery1.Active = False) then
begin
LoadDBTables();
end;
end;
procedure TTablesDirectoryForm.SearchEditChange(Sender: TObject);
begin
Dataform.TablesQuery1.Locate('name',SearchEdit.text,[loCaseInsensitive, loPartialKey]);
TableList.KeyValue := DataForm.TablesQuery1.FieldByName('name').asString;
LoadTableColumns(TableList.Items[TableList.ItemIndex]);
end;
procedure TTablesDirectoryForm.ColumnsListKeyDown(Sender: TObject;
var Key: Word; Shift: TShiftState);
begin
if (Key = VK_A) and (ssCtrl in Shift) then
begin
AddTextToMainFormScriptSQLEdit(ColumnsList.Items[ColumnsList.ItemIndex]);
Key := 0;
end;
end;
procedure TTablesDirectoryForm.TableListClick(Sender: TObject);
begin
Dataform.TablesQuery1.Locate('name',TableList.Items[TableList.ItemIndex],[]);
LoadTableColumns(TableList.Items[TableList.ItemIndex]);
end;
procedure TTablesDirectoryForm.TableListKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if (Key = VK_A) and (ssCtrl in Shift) then
begin
AddTextToMainFormScriptSQLEdit(TableList.Items[TableList.ItemIndex]);
Key := 0;
end;
end;
procedure TTablesDirectoryForm.AddTextToMainFormScriptSQLEdit(const TextToAdd: string);
var
MainForm: TMainForm;
CursorPos: Integer;
begin
// Assuming the modal form was called from MainForm
MainForm := TMainForm(Owner); // Ensure the Owner is set to the main form
if Assigned(MainForm) then
begin
with TargetEdit do
begin
CursorPos := SelStart; // Get the current cursor position
Text := Copy(Text, 1, CursorPos) + TextToAdd + Copy(Text, CursorPos + 1, MaxInt);
SelStart := CursorPos + Length(TextToAdd); // Move the cursor after the inserted text
end;
end;
end;
end.