gpt4 book ai didi

delphi - TControl 作为 TPicture?

转载 作者:行者123 更新时间:2023-12-02 05:30:24 25 4
gpt4 key购买 nike

我正在遍历表单的控制列表,当我找到 TPicture 时,我想更改属性(图像,但任何示例都可以)。

我该如何编码? TPciture 和 TControl 似乎不兼容。我可以以某种方式转换吗?

<小时/>

更新: 当我添加此代码时

for i:= 0 to Pred(designerForm.ControlCount) do
if designerForm.Controls[i] is TPicture then
MessageDlg('Picture : ' + designerForm.Controls[i].name,
mtInformation, [mbOK], 0);

其中designerForm是TForm,我在D7中从零到两个错误

[Error] PictureInspEditor.pas(121): Incompatible types: 'TPicture' and 'TControl'
[Fatal Error] E_logger.dpr(22): Could not compile used unit 'PictureInspEditor.pas'

最佳答案

当你说TPicture时,你确定你真的想说TImage吗? ?,无论如何,无论如何,首先您必须检查当前控件是否属于您想要评估的类 TImage (在本例中),然后您可以以这种方式进行转换 TImage(Controls[i ])

检查此示例中的 TImage

var
i : Integer;
begin
for i := 0 to ControlCount-1 do
if Controls[i] is TImage then
begin
// do your stuff here
TImage(Controls[i]).Picture:=aValue;
end;
end;

更新 您无法使用 is 运算符TPicture 类与 TControl 进行比较,因为 TPicture 的类型是与TControl无关。

来自 Embarcadero文档

The is Operator .....If the declared type of object is unrelated to class - that is, if the types are distinct and one is not an ancestor of the other a compilation error results

关于delphi - TControl 作为 TPicture?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5672039/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com