gpt4 book ai didi

delphi - 动态创建 Tpagecontrol 实例

转载 作者:行者123 更新时间:2023-12-03 19:13:07 25 4
gpt4 key购买 nike

我已经搜索和搜索,但没有找到示例。我想动态创建PageControl每个实例都有自己的偏移量TTabsheets .我没有收到来自 Delphi IDE 的任何投诉,但是我确实得到了:

Access violation in module FormApplication.exe write of address 00000000



有什么我想念的吗?
procedure TForm1.FormCreate(Sender: TObject);
type
ABC_Status_Object = record
ABC_PageControl_instance: TPageControl;
quickStat_instance: TTabsheet;
detailStat_instance: TTabsheet;
abc_light: TShape;
end;

var
ABC_Status: array of ABC_Status_Object;
I: Integer;
Frac, Icnt: Extended;

begin
inifile := TIniFile.Create(ChangeFileExt(Application.ExeName,'.ini'));
loadGlobalConfig;

Frac := 100/NUM/100;
for I := 0 to NUM do
begin
{// Create the Tabs: }
ABC_Status[I].ABC_PageControl_instance := TPageControl.Create(self);
ABC_Status[I].ABC_PageControl_instance.Parent := self;
ABC_Status[I].quickStat_instance := TTabsheet.Create(ABC_Status[I].ABC_PageControl_instance);
ABC_Status[I].detailStat_instance := TTabsheet.Create(ABC_Status[I].ABC_PageControl_instance);
ABC_Status[I].quickStat_instance.PageControl := ABC_Status[I].ABC_PageControl_instance;
ABC_Status[I].detailStat_instance.PageControl := ABC_Status[I].ABC_PageControl_instance;

{// Set the attributes of each instance of PageControl, including the tabs: }
ABC_Status[I].ABC_PageControl_instance.Visible := TRUE;
ABC_Status[I].ABC_PageControl_instance.Top := 0;
if(NUM = 1) then
ABC_Status[I].ABC_PageControl_instance.Width := ClientWidth;

if(NUM > 1) AND (NUM < 4) then
begin
Icnt := 100/(I+1)/100;

ABC_Status[I].ABC_PageControl_instance.Width := Trunc(ClientWidth*Frac);
ABC_Status[I].ABC_PageControl_instance.Left := 30;
end;
ABC_Status[I].quickStat_instance.Caption := 'Quick Status';
ABC_Status[I].quickStat_instance.Visible := TRUE;
ABC_Status[I].detailStat_instance.Caption := 'Details';
ABC_Status[I].detailStat_instance.Visible := TRUE;
end;

end;

最佳答案

您没有分配数组。在访问数组之前,您需要添加以下内容:

SetLength(ABC_Status, NUM+1);
+1是因为您使用了相当非标准的循环边界。

还有 100/100 = 1所以表达式 100/NUM/100看起来很奇怪。你也可以写 1/NUM .

您使用的非标 Extended类型似乎也很奇怪。我认为没有太大必要。

可能还有更多错误,但我在这里停下来。

关于delphi - 动态创建 Tpagecontrol 实例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47912368/

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