📄 sctvopt.pas
字号:
if List.Selected[Spot] then SList.Add(List.Items[Spot]);
end;
DSG := GetDataSourceGuide(GetFullDSName);
for Spot := 0 to SList.Count - 1 do
begin
VarName := SList[Spot];
if VarName <> '' then
begin
rvar := TSctDBVar.Create(PageManager.Page.Owner);
SctAutoSetComponentName(rvar, 'DB'+VarName, False);
rvar.Parent := TSctGroupPage(PageManager.Page);
rvar.DataSource := DSG.DataSource;
rvar.updatelevel := DSG.UpdateLevel;
rvar.DataField := VarName;
end;
end;
SList.Free;
if PageManager <> nil then PageManager.PageDesigner.Modified;
RefreshLists;
Inc(Current);
for Spot := Current to DBVarList.Items.Count do
begin
DBVarList.Selected[Spot-1] := True;
end;
DBVarList.ItemIndex := DBVarList.Items.Count - 1;
DBVarListClick(DBVarList);
end;
end;
{$endif}
procedure TSctDSVariableOptions.DeleteETList(ListBox: TListBox);
var
List: TStringList;
Spot: Integer;
MyVar: TSctVar;
Ancestor: Boolean;
begin
SelectComponent(nil);
List := TStringList.Create;
for Spot := 0 to ListBox.Items.Count - 1 do
begin
if ListBox.Selected[Spot] then List.Add(ListBox.Items[Spot])
end;
Ancestor := False;
for Spot := 0 to List.Count - 1 do
begin
MyVar := GetVar(List[Spot]);
if AceIsAncestor(MyVar) then Ancestor := True
else DeleteVar(MyVar);
end;
List.Free;
RefreshLists;
PageManager.PageDesigner.Modified;
if Ancestor then ShowMessage('Selection contains a component introduced in an '
+ 'ancestor form which cannot be deleted');
end;
procedure TSctDSVariableOptions.RevertDsgItemClick(Sender: TObject);
{$ifdef AceBDE}
var
DSG: TSctDataSourceGuide;
List: TList;
Spot: Integer;
begin
Dsg := GetDataSourceGuide(GetFullDSName);
if Dsg <> nil then
begin
List := TList.Create;
AceRevertToAncestor(Dsg, PageManager.PageDesigner);
FillDsgVarList(Dsg, List);
for Spot := 0 to List.Count - 1 do
AceRevertToAncestor(TSctVar(List.Items[Spot]), PageManager.PageDesigner);
List.Free;
end;
{$else}
begin
{$endif}
end;
procedure TSctDSVariableOptions.DSListPopupPopup(Sender: TObject);
var
pg: TSctPage;
MenuItem: TMenuItem;
Spot: Integer;
begin
{$ifdef WIN32}
RevertDsgItem.Visible := True;
{$else}
RevertDsgItem.Visible := False;
{$endif}
pg := GetGroupPage;
AddDsgItem.Visible := pg.NoDsgList.Count > 0;
{$ifdef AceBDE}
while AddDsgItem.Count > 0 do
begin
AddDsgItem.Delete(0);
end;
for Spot := 0 to pg.NoDsgList.Count - 1 do
begin
MenuItem := TMenuItem.Create(Self);
MenuItem.Caption := pg.NoDsgList[Spot];
MenuItem.OnClick := AddDsgItemClick;
AddDsgItem.Add(MenuItem);
end;
{$endif}
end;
procedure TSctDSVariableOptions.DBVarListClick(Sender: TObject);
var
DBItem: TDBItem;
begin
if DBVarList.ItemIndex <> -1 then
begin
if DBVarList.ItemIndex < DBList.Count then
begin
DBItem := TDBItem(DBList.Items[ DBVarList.ItemIndex ]);
SelectComponent(GetVar(DBItem.DBName));
end;
end;
UnSelectStuff(Sender);
end;
procedure TSctDSVariableOptions.DBVarListDragOver(Sender, Source: TObject;
X, Y: Integer; State: TDragState; var Accept: Boolean);
begin
Accept := (Source = clist) or (Source = flist);
end;
procedure TSctDSVariableOptions.DBVarListDragDrop(Sender, Source: TObject;
X, Y: Integer);
begin
AddManualDBVar(TListBox(Source));
end;
procedure TSctDSVariableOptions.DBVarListDrawItem(Control: TWinControl;
Index: Integer; Rect: TRect; State: TOwnerDrawState);
var
r1, r2, r3, r4: TRect;
Text: String;
DBItem: TDBItem;
w: Integer;
begin
DBItem := TDBItem(DBList.Items[Index]);
r1 := Rect;
r2 := Rect;
r3 := Rect;
r4 := Rect;
r1.Left := r1.Left + 4;
r1.Right := r1.Left + Round(Control.Width * 0.25);
r2.Left := r1.Right+1;
w := (r2.Right - r2.Left) div 4;
r2.Right := r2.Left + w;
r3.Left := r2.Right + 1;
r3.Right := r3.Left+w;
r4.Left := r3.Right + 1;
DBLabel.Left := r1.Left;
DBSourceLabel.Left := r2.Left;
DBFieldLabel.Left := r3.Left;
DBLevelLabel.Left := r4.Left;
with (Control as TListBox).Canvas do
begin
Text := DBItem.DBName;
if DBItem.Used then
begin
if (odSelected in State) then Brush.Color := clGreen
else Font.Color := clGreen;
Text := '> ' + Text;
end;
FillRect(Rect);
TextRect(r1, r1.Left+2, r1.Top+1, Text);
TextRect(r2, r2.Left+2, r2.Top+1, DBItem.DataSourceName);
TextRect(r3, r3.Left+2, r3.Top+1, DBItem.DataField);
Text := DBItem.LevelName;
if Not DBItem.LevelMatch then
begin
if (odSelected in State) then Brush.Color := clRed
else Font.Color := clRed;
Text := '* ' + Text;
end;
TextRect(r4, r4.Left+2, r4.Top+1, Text);
end;
end;
procedure TSctDSVariableOptions.DBDeleteClick(Sender: TObject);
begin
DeleteETList(DBVarList);
end;
procedure TSctDSVariableOptions.DBSelectUnusedClick(Sender: TObject);
begin
SelectUnused(DBVarList);
end;
procedure TSctDSVariableOptions.DBSelectAllClick(Sender: TObject);
begin
SelectAll(DBVarList);
end;
procedure TSctDSVariableOptions.DBListPopupPopup(Sender: TObject);
begin
DBDelete.Enabled := DBVarList.SelCount > 0;
DBSelectAll.Enabled := DBVarList.Items.Count > 0;
DBSelectUnused.Enabled := DBVarList.Items.Count > 0;
end;
procedure TSctDSVariableOptions.Add1Click(Sender: TObject);
{$ifdef AceBDE}
var
rvar: TSctDBVar;
{$endif}
begin
{$ifdef AceBDE}
if PageManager <> nil then
begin
rvar := TSctDBVar.Create(PageManager.Page.Owner);
SctAutoSetComponentName(rvar, 'DB', False);
rvar.Parent := TSctGroupPage(PageManager.Page);
rvar.updatelevel := TSctGroupPage(PageManager.Page).Detail.UpdateLevel;
PageManager.PageDesigner.Modified;
RefreshLists;
end;
{$endif}
end;
procedure TSctDSVariableOptions.SetMyButton(btn: TSpeedButton; Sender: TObject; var Zoomed: Boolean);
begin
if Sender = btn then Zoomed := Not Zoomed
else Zoomed := False;
if Zoomed then btn.Glyph.Assign(ZoomOut.Glyph)
else btn.Glyph.Assign(ZoomIn.Glyph);
end;
procedure TSctDSVariableOptions.DataSourceZoomClick(Sender: TObject);
begin
SetMyButton(DataSourceZoom, Sender, DataSourceZoomed);
SetMyButton(ExprZoom, Sender, ExprZoomed);
SetMyButton(TotalZoom, Sender, TotalZoomed);
SetMyButton(DBVarZoom, Sender, DBVarZoomed);
FormResize(Self);
end;
procedure TSctDSVariableOptions.FieldZoomClick(Sender: TObject);
begin
SetMyButton(FieldZoom, Sender, FieldZoomed);
SetMyButton(VarZoom, Sender, VarZoomed);
FormResize(Self);
end;
procedure TSctDSVariableOptions.DataSourceListMouseUp(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
{$ifdef AceBDE}
var
Dsg: TSctDataSourceGuide;
DsgItem: TDsgItem;
Done: Boolean;
Spot: Integer;
function InRect(Rect: TRect): Boolean;
begin
Result := (x >= Rect.Left) And (x <= Rect.Right) And
(y >= Rect.Top) And (y <= Rect.Bottom);
end;
begin
Spot := 0;
Done := False;
while Not Done And (Spot < DsgList.Count) do
begin
DsgItem := DsgList.Items[Spot];
if InRect(DsgItem.CheckRect) then
begin
Done := True;
DSG := GetDataSourceGuide(DsgItem.DataSourceName);
if DSG <> nil then
begin
if Not AceIsAncestor(DSG) then
begin
Dsg.CreateVariables := Not Dsg.CreateVariables;
UpdateDSG(DSG);
UpdateCFList;
end;
end;
end;
Inc(Spot);
end;
{$else}
begin
{$endif}
end;
procedure TSctDSVariableOptions.Button3Click(Sender: TObject);
begin
{$ifdef AceBDE}
Optimize;
{$endif}
end;
{$ifdef AceBDE}
procedure TSctDSVariableOptions.Optimize;
var
DSG: TSctDataSourceGuide;
dsgSpot, Spot: Integer;
DBVars,UsedDsgList: TList;
MyVar: TSctDBVar;
pg: TSctGroupPage;
DSName: String;
begin
if Application.MessageBox('This will delete any unused auto dbvars.' +
' If you use any variables in code, I cannot detect that. Optimize?'
, 'Confirm Optimize?', MB_YESNO) = ID_YES then
begin
pg := GetGroupPage;
SelectComponent(nil);
DBVars := TList.Create;
UsedDsgList := TList.Create;
if pg.DataSourceList <> nil then
begin
for dsgSpot := 0 to pg.DataSourceList.Count - 1 do
begin
DSG := pg.DataSourceList.Items[dsgSpot];
if DSG <> nil then
begin
if Not AceIsAncestor(DSG) then
begin
UsedDsgList.Add(Dsg);
DBVars.Clear;
FillDSGVarList(DSG, DBVars);
DSG.CreateVariables := False;
for Spot := 0 to DBVars.Count - 1 do
begin
MyVar := DBVars.Items[Spot];
if Not VarUsed(MyVar) then
begin
DeleteVar(MyVar);
end;
end;
end;
end;
end;
end;
for dsgSpot := 0 to UsedDsgList.Count - 1 do
begin
DSG := UsedDsgList.Items[dsgSpot];
DBVars.Clear;
FillDSGVarList(DSG, DBVars);
if DBVars.Count = 0 then
begin
SelectComponent(nil);
if Dsg.DataSource <> nil then
begin
DSName := pg.FullDSNames[ pg.FullDSList.IndexOf(DSG.DataSource) ];
pg.NoDsgList.Add(DSName);
end;
Dsg.Parent := nil;
Dsg.Free;
end;
end;
DBVars.Free;
pg.UpdateVarList;
UpdateVars;
RefreshLists;
PageManager.PageDesigner.Modified;
end;
end;
{$endif}
procedure TSctDSVariableOptions.DeleteDsgItemClick(Sender: TObject);
{$ifdef AceBDE}
var
DSG: TSctDataSourceGuide;
List: TList;
Spot: Integer;
pg: TSctPage;
UsedVar: Boolean;
DSName: String;
begin
Dsg := GetDataSourceGuide(GetFullDSName);
if Dsg <> nil then
begin
if AceIsAncestor(Dsg) then ShowMessage('Selection contains a component introduced in an '
+ 'ancestor form which cannot be deleted')
else
begin
SelectComponent(nil);
List := TList.Create;
FillDsgVarList(Dsg, List);
Spot := 0;
UsedVar := False;
while (Spot < List.Count) And (Not UsedVar) do
begin
if VarUsed(List.Items[Spot] )then UsedVar := True
else Inc(Spot);
end;
if UsedVar then
begin
if Application.MessageBox('There are variables that are being used from this DataSource.'
, 'Confirm Delete?', MB_YESNO) = ID_YES then
begin
UsedVar := False;
end;
end;
if Not UsedVar then
begin
pg := GetGroupPage;
if Dsg.DataSource <> nil then
begin
DSName := pg.FullDSNames[ pg.FullDSList.IndexOf(DSG.DataSource) ];
pg.NoDsgList.Add(DSName);
end;
for Spot := 0 to List.Count - 1 do DeleteVar(List.Items[Spot]);
Dsg.Parent := nil;
Dsg.Free;
pg.UpdateVarList;
UpdateVars;
RefreshLists;
PageManager.PageDesigner.Modified;
List.Free;
end;
end;
end;
{$else}
begin
{$endif}
end;
procedure TSctDSVariableOptions.AddDsgItemClick(Sender: TObject);
var
pg: TSctPage;
Spot: Integer;
begin
pg := GetGroupPage;
Spot := pg.NoDsgList.IndexOf(TMenuItem(Sender).Caption);
if Spot <> -1 then pg.NoDsgList.Delete(Spot);
PageManager.PageDesigner.Modified;
pg.UpdateVarList;
UpdateVars;
RefreshLists;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -