📄 jvtimerlistform.pas
字号:
begin
Caption := Format(srTimerEvents, [TimersCollection.Name]);
Empty := TimersCollection.Events.Count = 0;
end
else
Empty := True;
if Empty then
begin
DrawGrid.RowCount := 2;
SelectItem(nil);
end
else
DrawGrid.RowCount := TimersCollection.Events.Count + 1;
DeleteBtn.Enabled := not Empty;
ClearBtn.Enabled := not Empty;
DeleteMenu.Enabled := not Empty;
CopyMenu.Enabled := not Empty;
CutMenu.Enabled := not Empty;
PasteMenu.Enabled := ClipboardComponents;
DrawGrid.Invalidate;
end;
function TJvTimerItemsEditor.GetForm: TCustomForm;
begin
Result := {$IFDEF COMPILER6_UP} TCustomForm(Designer.Root) {$ELSE} Designer.Form {$ENDIF};
end;
procedure TJvTimerItemsEditor.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Action := caFree;
end;
function TJvTimerItemsEditor.CheckCollection: Boolean;
begin
Result := (TimersCollection <> nil) and (TimersCollection.Owner <> nil)
and ({$IFDEF COMPILER6_UP} Designer.Root {$ELSE} Designer.Form {$ENDIF} <> nil);
end;
{$IFDEF COMPILER6_UP}
type
TDesignerSelectionList = IDesignerSelections;
{$ENDIF}
procedure TJvTimerItemsEditor.SelectItem(Item: TJvTimerEvent);
var
FComponents: TDesignerSelectionList;
begin
if CheckCollection and Active then
begin
FComponents := {$IFDEF COMPILER6_UP} TDesignerSelections {$ELSE} TDesignerSelectionList {$ENDIF}.Create;
if Item <> nil then
FComponents.Add(Item)
else
FComponents.Add(TimersCollection);
SetSelection(FComponents);
end;
end;
function TJvTimerItemsEditor.ItemByRow(Row: Integer): TJvTimerEvent;
begin
Result := nil;
if CheckCollection and (Row >= 0) and
(Row < TimersCollection.Events.Count) then
begin
Result := TJvTimerEvent(TimersCollection.Events[Row]);
end;
end;
{$IFDEF COMPILER6_UP}
procedure TJvTimerItemsEditor.ItemDeleted(const ADesigner: IDesigner; Item: TPersistent);
begin
if Item = TimersCollection then
begin
{$ELSE}
procedure TJvTimerItemsEditor.ComponentDeleted(Component: IPersistent);
begin
if ExtractPersistent(Component) = TimersCollection then
begin
{$ENDIF}
TimersCollection := nil;
Close;
end;
end;
procedure TJvTimerItemsEditor.DrawGridDrawCell(Sender: TObject; Col,
Row: Longint; Rect: TRect; State: TGridDrawState);
var
CellText: string;
Item: TJvTimerEvent;
begin
CellText := '';
if gdFixed in State then
CellText := 'Item name'
else
begin
Item := ItemByRow(Row - 1);
if Item <> nil then
CellText := Item.DisplayName;
end;
DrawCellText(DrawGrid, Col, Row, CellText, Rect, taLeftJustify, vaCenterJustify);
end;
procedure TJvTimerItemsEditor.DrawGridSelectCell(Sender: TObject; Col,
Row: Longint; var CanSelect: Boolean);
begin
SelectItem(ItemByRow(Row - 1));
end;
procedure TJvTimerItemsEditor.CloseBtnClick(Sender: TObject);
begin
Close;
end;
procedure TJvTimerItemsEditor.DeleteClick(Sender: TObject);
var
Item: TJvTimerEvent;
begin
Item := ItemByRow(DrawGrid.Row - 1);
if Item <> nil then
begin
{$IFDEF COMPILER6_UP} TCustomForm(Designer.Root).Designer {$ELSE} Designer {$ENDIF}.ValidateRename(Item.TimerList, Item.DisplayName, '');
TimersCollection.Delete(Item.Handle);
if TimersCollection.Count > 0 then
begin
Item := ItemByRow(DrawGrid.Row - 1);
SelectItem(Item);
end
else
SelectItem(nil);
UpdateData;
Designer.Modified;
end;
end;
procedure TJvTimerItemsEditor.DrawGridKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if Shift = [] then
case Key of
VK_RETURN:
if ItemByRow(DrawGrid.Row - 1) <> nil then
ActivateInspector(#0);
VK_DELETE:
DeleteClick(nil);
end;
end;
procedure TJvTimerItemsEditor.FormCreate(Sender: TObject);
begin
TimersCollection := nil;
if NewStyleControls then
Font.Style := [];
with FormStorage do
begin
UseRegistry := True;
IniFileName := SDelphiKey;
end;
end;
procedure TJvTimerItemsEditor.FormResize(Sender: TObject);
begin
with DrawGrid do
ColWidths[0] := ClientWidth;
end;
{$IFDEF COMPILER6_UP}
function TJvTimerItemsEditor.EditAction(Action: TEditAction): Boolean;
begin
Result := True;
{$ELSE}
procedure TJvTimerItemsEditor.EditAction(Action: TEditAction);
begin
{$ENDIF}
case Action of
eaCut:
Cut;
eaCopy:
Copy;
eaPaste:
Paste;
eaDelete:
DeleteClick(Self);
end;
end;
procedure TJvTimerItemsEditor.NewClick(Sender: TObject);
var
I: Integer;
Item: TJvTimerEvent;
begin
Item := TJvTimerEvent.Create(TimersCollection.Owner);
if Item <> nil then
try
Item.Name := UniqueName(Item);
with TimersCollection do
I := ItemIndexByHandle(AddItem(Item));
SelectItem(Item);
Designer.Modified;
ActivateInspector(#0);
DrawGrid.Row := I + 1;
except
Item.Free;
raise;
end
else
raise EJVCLException.Create(srEventNotCreate);
end;
procedure TJvTimerItemsEditor.CutClick(Sender: TObject);
begin
Cut;
UpdateData;
end;
procedure TJvTimerItemsEditor.CopyClick(Sender: TObject);
begin
Copy;
UpdateData;
end;
procedure TJvTimerItemsEditor.PasteClick(Sender: TObject);
begin
Paste;
UpdateData;
end;
procedure TJvTimerItemsEditor.Cut;
begin
Copy;
DeleteClick(Self);
end;
procedure TJvTimerItemsEditor.Copy;
var
CompList: TDesignerSelectionList;
Item: TJvTimerEvent;
begin
CompList := {$IFDEF COMPILER6_UP} TDesignerSelections {$ELSE} TDesignerSelectionList {$ENDIF}.Create;
{$IFNDEF COMPILER6_UP}
try
{$ENDIF}
Item := ItemByRow(DrawGrid.Row - 1);
if Item <> nil then
begin
CompList.Add(Item);
CopyComponents(OwnerForm, CompList);
end;
{$IFNDEF COMPILER6_UP}
finally
CompList.Free;
end;
{$ENDIF}
end;
procedure TJvTimerItemsEditor.Paste;
var
CompList: TDesignerSelectionList;
begin
if CheckCollection then
begin
CompList := {$IFDEF COMPILER6_UP} TDesignerSelections {$ELSE} TDesignerSelectionList {$ENDIF}.Create;
{$IFNDEF COMPILER6_UP}
try
{$ENDIF}
PasteComponents(OwnerForm, TimersCollection, CompList);
UpdateData;
{$IFNDEF COMPILER6_UP}
finally
CompList.Free;
end;
{$ENDIF}
end;
end;
procedure TJvTimerItemsEditor.ClearBtnClick(Sender: TObject);
var
Item: TJvTimerEvent;
begin
while TimersCollection.Events.Count > 0 do
begin
Item := TJvTimerEvent(TimersCollection.Events[0]);
if Item <> nil then
{$IFDEF COMPILER6_UP} TCustomForm(Designer.Root).Designer {$ELSE} Designer {$ENDIF}.ValidateRename(Item,
Item.Name, '');
TimersCollection.Events.Delete(0);
Item.Free;
end;
UpdateData;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -