📄 listactns.pas
字号:
FSortType := stNone;
end;
{ TCustomListAction }
constructor TCustomListAction.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FItemIndex := -1;
DisableIfNoHandler := False;
Enabled := True;
Active := True;
end;
procedure TCustomListAction.ExecuteTarget(Target: TObject);
var
I: Integer;
begin
if FInUpdate then exit;
FInUpdate := True;
try
if Target is TCustomListControl then
begin
FItemIndex := TCustomListControl(Target).ItemIndex;
for I := 0 to FClients.Count - 1 do
if (TBasicActionLink(FClients[I]) is TListActionLink) and
(TListActionLink(FClients[I]).FClient <> Target) then
with Target as TCustomListControl do
TListActionLink(FClients[I]).SetItemIndex(ItemIndex);
end;
if Assigned(FOnItemSelected) then
FOnItemSelected(Self, Target as TControl);
finally
FInUpdate := False;
end;
end;
function TCustomListAction.GetCount: Integer;
begin
Result := -1;
if Assigned(FOnGetItemCount) then
FOnGetItemCount(Self, Result);
end;
function TCustomListAction.GetString(Index: Integer): String;
begin
Result := '';
end;
function TCustomListAction.HandlesTarget(Target: TObject): Boolean;
begin
Result := True;
end;
procedure TCustomListAction.Loaded;
begin
inherited Loaded;
if FActivated then
SetActive(FActivated);
if Assigned(FLoadedImages) then
SetImages(FLoadedImages);
end;
procedure TCustomListAction.SetActive(const Value: Boolean);
var
I: Integer;
begin
if Value and (csLoading in ComponentState) then
begin
FActivated := Value;
exit;
end;
if FActive <> Value then
begin
FActive := Value;
for I := 0 to FClients.Count - 1 do
if TBasicActionLink(FClients[I]) is TListActionLink then
begin
FLoading := True;
try
TListActionLink(FClients[I]).SetActive(Value);
finally
FLoading := False;
end;
end;
Change;
if FItemIndex <> -1 then
SetItemIndex(FItemIndex);
end;
end;
procedure TCustomListAction.SetImages(const Value: TCustomImageList);
var
I: Integer;
begin
if Assigned(Value) and (csLoading in ComponentState) then
begin
FLoadedImages := Value;
exit;
end;
if FImages <> Value then
begin
FImages := Value;
for I := 0 to FClients.Count - 1 do
if TBasicActionLink(FClients[I]) is TListActionLink then
TListActionLink(FClients[I]).SetImages(Value);
end;
end;
procedure TCustomListAction.SetItemIndex(const Value: Integer);
var
I: Integer;
begin
if not Active then exit;
for I := 0 to FClients.Count - 1 do
if TBasicActionLink(FClients[I]) is TListActionLink then
TListActionLink(FClients[I]).SetItemIndex(Value);
FItemIndex := Value;
end;
procedure TCustomListAction.SetString(Index: Integer; const Value: String);
begin
end;
{ TVirtualListAction }
function TVirtualListAction.GetItem(const Index: Integer; var Value: String;
var ImageIndex: Integer; var Data: Pointer): Boolean;
begin
Result := False;
if Count <= 0 then exit;
Result := Assigned(FOnGetItem);
if Result then
FOnGetItem(Self, Index, Value, ImageIndex, Data);
end;
function TVirtualListAction.GetString(Index: Integer): String;
var
ImageIndex: Integer;
Data: Pointer;
begin
if (Index < Count) and (Count > 0) then
begin
if Assigned(FOnGetItem) then
FOnGetItem(Self, Index, Result, ImageIndex, Data)
else
raise Exception.Create(SNoGetItemEventHandler);
end
else
raise Exception.CreateFmt(SListIndexError, [Index]);
end;
{ TStaticListItems }
type
TWinControlActionLinkType = class(TWinControlActionLink);
TCustomListViewClass = class(TCustomListView);
procedure TStaticListItems.Notify(Item: TCollectionItem;
Action: TCollectionNotification);
var
I: Integer;
begin
case Action of
cnAdded:
begin
if not Assigned(FStaticListAction) or not FStaticListAction.Active then exit;
for I := 0 to FStaticListAction.FClients.Count - 1 do
with TWinControlActionLinkType(FStaticListAction.FClients[I]) do
begin
if FClient is TCustomComboBoxEx then
with FClient as TCustomComboBoxEx do
with ItemsEx.Add do
begin
Caption := TListControlItem(Item). Caption;
ImageIndex := TListControlItem(Item).ImageIndex;
Data := TListControlItem(Item).Data;
end
else if FClient is TCustomListView then
with TCustomListViewClass(FClient).Items.Add do
begin
Caption := TListControlItem(Item).Caption;
ImageIndex := TListControlItem(Item).ImageIndex;
Data := TListControlItem(Item).Data;
end;
end;
end;
cnDeleting:
begin
if not Assigned(FStaticListAction) or not FStaticListAction.Active then exit;
for I := 0 to FStaticListAction.FClients.Count - 1 do
with TWinControlActionLinkType(FStaticListAction.FClients[I]) do
begin
if FClient is TCustomComboBoxEx then
TCustomComboBoxEx(FClient).Items.Delete(Item.Index)
else if FClient is TCustomListView then
TCustomListViewClass(FClient).Items.Delete(Item.Index);
end;
end;
end;
end;
procedure TStaticListItems.Update(Item: TCollectionItem);
var
I: Integer;
begin
inherited Update(Item);
if not Assigned(FStaticListAction) or not Assigned(Item) or
not FStaticListAction.Active or FStaticListAction.Loading then exit;
for I := 0 to FStaticListAction.FClients.Count - 1 do
with TWinControlActionLinkType(FStaticListAction.FClients[I]) do
begin
if FClient is TCustomComboBoxEx then
with FClient as TCustomComboBoxEx do
with ItemsEx[Item.Index] do
begin
Caption := TListControlItem(Item). Caption;
ImageIndex := TListControlItem(Item).ImageIndex;
Data := TListControlItem(Item).Data;
end
else if FClient is TCustomListView then
with TCustomListViewClass(FClient).Items[Item.Index] do
begin
Caption := TListControlItem(Item).Caption;
ImageIndex := TListControlItem(Item).ImageIndex;
Data := TListControlItem(Item).Data;
end;
end;
end;
{ TStaticListAction }
constructor TStaticListAction.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FListItems := TStaticListItems.Create(Self, GetItemClass);
FListItems.FStaticListAction := Self;
end;
destructor TStaticListAction.Destroy;
begin
FreeAndNil(FListItems);
inherited Destroy;
end;
function TStaticListAction.GetCount: Integer;
begin
Result := FListItems.Count;
end;
function TStaticListAction.GetItem(const Index: Integer; AnItem: TListControlItem): Boolean;
begin
Result := (Index >= 0) and (Index < FListItems.Count);
if not Result then exit;
AnItem.Assign(FListItems[Index]);
if Assigned(FOnGetItem) then
FOnGetItem(Self, Index, AnItem);
end;
function TStaticListAction.GetItemClass: TListControlItemClass;
begin
Result := TListControlItem;
end;
function TStaticListAction.GetString(Index: Integer): String;
begin
Result := Items[Index].Caption;
end;
procedure TStaticListAction.SetListitems(const Value: TStaticListItems);
begin
FListItems.Assign(Value);
end;
procedure TStaticListAction.SetString(Index: Integer; const Value: String);
begin
Items[Index].Caption := Value;
end;
{ TListActionLink }
function TListActionLink.IsActiveLinked: Boolean;
begin
Result := Action is TCustomListAction;
end;
function TListActionLink.IsImagesLinked: Boolean;
begin
Result := Action is TCustomListAction and
Assigned(TCustomListAction(Action).FImages);
end;
procedure TListActionLink.SetAction(Value: TBasicAction);
begin
inherited SetAction(Value);
if FClient is TCustomListControl then
if FAction is TCustomListAction then
if TCustomListAction(FAction).Active then
RefreshControl;
end;
procedure TListActionLink.SetActive(const Value: Boolean);
begin
if not Value then
begin
if (FClient is TCustomListControl) then
TCustomListControl(FClient).Clear;
exit;
end;
if Value and (FAction is TCustomListAction) and
not TCustomListAction(FAction).Active then exit;
if Action is TCustomListAction then
RefreshControl;
end;
procedure TListActionLink.SetImages(Value: TCustomImageList);
begin
end;
procedure TListActionLink.RefreshControl;
var
I: Integer;
ACaption: String;
AImageIndex: Integer;
DataPtr: Pointer;
begin
if not (Action is TCustomListAction) then exit;
if FClient is TCustomListControl then
TCustomListControl(FClient).Clear;
if Action is TStaticListAction then
begin
with Action as TStaticListAction do
for I := 0 to Count - 1 do
if GetItem(I, Items[I]) then
AddItem(Items[I]);
end
else
if Action is TVirtualListAction then
for I := 0 to TCustomListAction(Action).Count - 1 do
with Action as TVirtualListAction do
if GetItem(I, ACaption, AImageIndex, DataPtr) then
AddItem(ACaption, AImageIndex, DataPtr);
end;
procedure TListActionLink.AddItem(AnItem: TListControlItem);
begin
end;
procedure TListActionLink.AddItem(ACaption: String; AImageIndex: Integer;
DataPtr: Pointer);
begin
end;
procedure TListActionLink.SetItemIndex(const Value: Integer);
begin
if FClient is TCustomListControl then
with FClient as TCustomListControl do
ItemIndex := Value;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -