如何在运行时创建的面板中创建组件?

时间:2016-12-10 06:10:34

标签: delphi

我想创建包含多个标签的面板组件。我的代码如下,面板已创建,但标签没有。错误消息是“地址0040452A的访问冲突...读取地址FFFFFFD0。”

Dim i,j,k,items(100),threshold(100),smartdata(10,11),t
Dim Des(10),Limit(10),Normal(10),Bad(10),Data(10),getinfo(10),status(10)
Dim strComputer,objWMIService,colItems,objItem

strComputer = "." 
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\WMI")

Set colItems = objWMIService.ExecQuery( _
    "SELECT * FROM MSStorageDriver_FailurePredictThresholds",,48) 
For Each objItem in colItems 'error line
    j=0
    For i=2 To UBound(objItem.VendorSpecific,1) Step 12
        items(j) = objItem.VendorSpecific(i)
        threshold(j) = objItem.VendorSpecific(i+1)
        j=j+1
    Next
Next

1 个答案:

答案 0 :(得分:5)

您不能将TPanel.Handle标记为TWinControl,因为它不是var Pnl: TPanel; begin Pnl := TPanel.Create(Self); with Pnl do begin Parent := ... // Other panel setup code end; with TLabel.Create(self) do begin Parent := Pnl; // Other label setup code end; end; 。它是一个窗口把手。

将本地参考保存到您正在创建的面板中,并将其用作标签的父级。

 $(document).on()
相关问题