- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我创建了一个自定义 Tpanel 并在里面放置了各种自定义组件......
procedure Panel_Comp(Location: TWinControl; NumOfComp: Integer;Left,Top,Height,width:Integer);
begin
MyPanel := TsPanel.Create(Conf);
MyPanel.Name := 'MyPanel' + IntToStr(NumOfComp);
MyPanel.Parent := Location;
MyPanel.Left := Left;
MyPanel.Top := Top;
MyPanel.Height := Height;
MyPanel.Width := width;
MyPanel.Caption := '';
end;
我是这样调用它的
Panel_Comp(Conf.ScrollBox1,1,8,10,70,322);
按照相同的逻辑,我在新面板中放入了其他自定义组件,包括具有 onclick 事件的 tBitbtn。
procedure BitBtn_Comp(Location: TWinControl; NumOfComp: Integer; Left,Top,Height,Width,ImageNum: Integer);
begin
MyBitBtn := TBitBtn.Create(Conf);
......
MyBitBtn.tag := NumOfComp;
MyBitBtn.OnClick:= Conf.CloseCurrentPanel;
end;
在主窗体中的TConf.CloseCurrentPanel;
procedure TConf.CloseCurrentPanel(Sender: TObject);
var
panelComp: TComponent;
begin
panelComp := FindComponentEx('Conf.MyPanel'+ IntToStr(TBitBtn(Sender).tag);
TPanel(panelComp).Free;
Application.ProcessMessages;
end;
当我调用它时,我遇到了访问冲突......我认为在释放面板之前我必须释放面板内的所有组件,但是我如何在面板之前释放 BitBtn 并继续点击事件的操作?
这是您需要的 FindComponetEx 函数...
function FindComponentEx(const Name: string): TComponent;
var
FormName: string;
CompName: string;
P: Integer;
Found: Boolean;
Form: TForm;
I: Integer;
begin
// Split up in a valid form and a valid component name
P := Pos('.', Name);
if P = 0 then
begin
raise Exception.Create('No valid form name given');
end;
FormName := Copy(Name, 1, P - 1);
CompName := Copy(Name, P + 1, High(Integer));
Found := False;
// find the form
for I := 0 to Screen.FormCount - 1 do
begin
Form := Screen.Forms[I];
// case insensitive comparing
if AnsiSameText(Form.Name, FormName) then
begin
Found := True;
Break;
end;
end;
if Found then
begin
for I := 0 to Form.ComponentCount - 1 do
begin
Result := Form.Components[I];
if AnsiSameText(Result.Name, CompName) then Exit;
end;
end;
Result := nil;
end;
最佳答案
出现 AV 是因为您正在破坏仍在处理 Windows 消息的组件 (MyBitBtn)。解决方案是通过 PostMessage
将销毁推迟到以后,类似于这样:
unit Unit1;
interface
uses
Windows,
Messages,
SysUtils,
Variants,
Classes,
Graphics,
Controls,
Forms,
Dialogs,
ExtCtrls,
StdCtrls;
const
UM_DESTROYPANEL = WM_APP + 623; // some "unique" number; UM = user message
type
TConf = class(TForm)
Panel1: TPanel;
Button1: TButton;
procedure Button1Click(Sender: TObject);
strict private
procedure UMDestroyPanel(var Message: TMessage); message UM_DESTROYPANEL;
public
{ Public-Deklarationen }
end;
var
Conf: TConf;
implementation
{$R *.dfm}
procedure TConf.Button1Click(Sender: TObject);
begin
PostMessage(Handle, UM_DESTROYPANEL, 0, 0);
end;
procedure TConf.UMDestroyPanel(var Message: TMessage);
begin
Panel1.Free;
end;
end.
如果需要,您可以使用 wParam 和 lParam 来传递参数,如下所示:
procedure TConf.Button1Click(Sender: TObject);
begin
PostMessage(Handle, UM_DESTROYPANEL, WPARAM(Panel1), 0);
end;
procedure TConf.UMDestroyPanel(var Message: TMessage);
begin
TObject(Message.WParam).Free;
end;
编辑:在您的情况下,我可能会像这样重写 TConf.CloseCurrentPanel
:
procedure TConf.CloseCurrentPanel(Sender: TObject);
var
panelComp: TComponent;
begin
panelComp := FindComponentEx('Conf.MyPanel'+ IntToStr(TBitBtn(Sender).Tag);
PostMessage(Handle, UM_DESTROYPANEL, WPARAM(panelComp), 0);
end;
或者,您可以通过标签(可能是更好的解决方案,因为涉及的转换较少):
procedure TConf.CloseCurrentPanel(Sender: TObject);
begin
PostMessage(Handle, UM_DESTROYPANEL, TBitBtn(Sender).Tag, 0);
end;
procedure TConf.UMDestroyPanel(var Message: TMessage);
var
panelComp: TComponent;
begin
panelComp := FindComponentEx('Conf.MyPanel'+ IntToStr(Message.WParam));
panelComp.Free;
end;
AFAICT 不需要 Application.ProcessMessages
。
关于windows - 我怎样才能释放一个 Tpanel 有一个 TbitBtn 调用释放 Tpanel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11877394/
我在另一个面板中有一个面板: 内部面板对齐alTop: 外部面板设置为AutoSize=true: 所有东西都有尺寸。如果我在设计时更改内部面板的高度,则外部面板自动调整大小以适应它: 现在运行时 现
我创建了一个自定义 Tpanel 并在里面放置了各种自定义组件...... procedure Panel_Comp(Location: TWinControl; NumOfComp: Int
我尝试在设计器中配置的 TPanel 上使用分配,但它不起作用。 var LPanel : TPanel; begin LPanel := TPanel.Create(nil); LPan
我正在使用 Josef Švejk's excellent answer 中的 DrawTextRotatedB 函数对于问题How to draw text in a canvas vertical
我正在使用 Josef Švejk's excellent answer 中的 DrawTextRotatedB 函数对于问题How to draw text in a canvas vertical
我的主窗体上有几个 TPanel,根据用户选择的选项显示/隐藏它们。问题是在设计时我必须不断地移动它们来编辑它们。其他人是否有更简单/更好的方法来处理这种情况? 最佳答案 如果一次只有一个面板可见,那
我怎样才能使 View 像黄色矩形一样。使用 TPanel + 颜色?如果是的话,文本从左侧缩进怎么样? 感谢您的帮助和建议! 最佳答案 最简单的方法是使用TPanel。将 ParentBackgro
我有一个基于 TPanel 的自定义组件。目的是在顶部显示一个所谓的“标题区域”,它显示标题并具有可自定义的边框和背景颜色。它工作正常,除了一个小问题:在设计时,当点击“标题区域”时,该组件未被选中(
我有几个在运行时填充有按钮的 TPanel。然而,我用来从父面板中释放按钮的下面的代码有时会生成访问冲突错误。 procedure TfrmTakeOrder.FreeItemButtons(butt
我需要在 TPanel 上绘制,最好是直接绘制,这样我上面就不会再有其他组件妨碍 mouseevent 事件捕获(我想在上面绘制一些“大小握把”)。我应该怎样做呢? 最佳答案 要真正做到正确,您可能应
我注意到,当我将 TPanel.FullRepaint 设置为 False 时,调整大小闪烁变得更好。由于该属性存在并且默认情况下为 True,因此一定有某种原因。 如何决定是否设置? 帮助仅指出:
我正在使用 Delphi 2010,如果我创建一个新的 VCL 应用程序,请将 TPanel 放在表单上并将其“color”属性设置为“clInactiveCaptionText”,它会显示正确的颜色
Delphi-版本5。我有一个正在组装的文件比较应用程序,它的主窗体上有一个左面板和右面板。每个面板(pnlLeft 和 pnlRight)都有相同范围的控件和事件,仅按名称分隔。即 btnCheck
如何创建一个行为类似于 Tpanel 的 TCustomControl?例如 MyCustomComponent,我可以将组件放入标签、图像等中。 最佳答案 诀窍是 TCustomPanel 中的这段
在我的主窗体上,我有一个 TPanel,其中包含充当工具栏的按钮。我想克隆/复制此工具栏和按钮及其功能到第二种形式。 使用 newmenu.merge(mainmenu) 克隆菜单很简单。这是复制 T
我想在一个窗体中间显示一个 TPanel,该窗体是其他窗体的 MDI 父窗体。某种“飞溅”形式,但不完全是。该面板将包含用户可以调用杂项的链接/按钮/快捷方式。功能。 主要要求是当我单击 MDI 子窗
我想知道“获取包管理器”窗口中的阴影效果是如何实现的。阴影区域标记为红色。 TPanel 中是否有任何属性可以实现此目的,或者是自定义绘制的? 最佳答案 TPanel 没有属性来创建该阴影。 使用 S
我找到了 another Delphi 5 和 Delphi XE6 之间的回归。 我有一个 TPanel,它被设置为其内容的 AutoSize 本身(面板为绿色): 当TPanel包含任何其他控件时
有几个第三方控件(例如 Raize Components )具有关闭的“十字”按钮“选项”(例如页面控件)。我的要求更简单,我想将右上角对齐的十字“按钮”放在 TPanel 上并访问其单击事件。是否有
有没有办法将文本包装在 Delphi 中的 TPanel.Caption 中(在我的例子中是 Delphi 6)? 最佳答案 恐怕不是默认情况下。从 TPanel 的源代码中可以看到,文本是由 Dra
我是一名优秀的程序员,十分优秀!