-1

尝试使用一些主模板来根据主编辑框中的数字更改组框的可见性。 EditDay是编辑框,里面只有数字

day:=DayOfTheYear(Now); 
EditDay.Text:=day;

所以它基本上是一年中的一天。无论如何,我一年中的每一天都需要一个组框(带有一些备忘录)。因为这是一个带有记录的文件,另一个程序会读取每天不同的信息,所以我首先需要那个文件编写器,所以我什至可以制作一个。这就是这个因为我正在做一个记录文件,在我写入文件之前必须先填满所有框,所以我需要让 Groupboxes 一次可见,每个一个我在 main 中指定的那一天TEdit。现在我坚持设置分组框的可见性;下面的代码给了我访问冲突错误。

xTEditnamed中指定的数字EditDay。我想y每隔一天做一个,但在 EditDay 盒子里的那一天,除了x

x : Integer;     
y : Integer;

procedure TWriteForm.DayCheckTimer(Sender: TObject);
begin
  x:=StrToInt(EditDay.Text);
  y:=Not x;
  (FindComponent('GroupBox'+IntToStr(x)) as TGroupBox).Visible := True;
  (FindComponent('GroupBox'+IntToStr(y)) as TGroupBox).Visible := False;

试图设置 y:=[1..365] 而不是 x; [1..365] - x; 和其他几个,但没有一个起作用。

我哪里错了?.. 任何帮助将不胜感激。:))

[我有点初学者,是的..]

4

2 回答 2

1

查看y:=不是x;在调试器中 x=1 将是 y=-2,您将找不到具有此名称的 Compoentr。

您将不得不迭代您的组件

For i := 1 to mCount

并按条件设置可见性

(FindComponent('GroupBox'+IntToStr(i)) as TGroupBox).Visible := y = i;
于 2012-11-05T23:48:43.313 回答
0

这里有一个小示例项目来处理很多(365)条记录。

unit RecordEdit_ViewU;

interface

uses
  SysUtils,
  Controls, Forms, Dialogs, StdCtrls, System.Classes;

type
  TPerson = record
    Firstname : string[50]; // shortstring !!
    Lastname : string[50];  // shortstring !!
  end;

  TRecordEdit_View = class( TForm )
    Current_Edit : TEdit;
    Data_Firstname_Edit : TEdit;
    Data_Lastname_Edit : TEdit;
    Data_Prev_Button : TButton;
    Data_Next_Button : TButton;
    Data_Save_Button : TButton;
    procedure FormCreate( Sender : TObject );
    procedure Current_EditChange( Sender : TObject );
    procedure Data_Prev_ButtonClick( Sender : TObject );
    procedure Data_Next_ButtonClick( Sender : TObject );
    procedure Data_Save_ButtonClick( Sender : TObject );
  private
    FData :    array [1 .. 365] of TPerson;
    FCurrent : Integer;
    procedure SetCurrent( const Value : Integer );
    procedure InitData;
    procedure StoreCurrent;
    procedure LoadCurrent;
    procedure SaveData;
  public
    property Current : Integer read FCurrent write SetCurrent;
  end;

var
  RecordEdit_View : TRecordEdit_View;

implementation

{$R *.dfm}

procedure TRecordEdit_View.Current_EditChange( Sender : TObject );
begin
  Current := StrToIntDef( Current_Edit.Text, 0 ); // convert text to integer
end;

procedure TRecordEdit_View.Data_Next_ButtonClick( Sender : TObject );
begin
  Current := Current + 1; // next record
end;

procedure TRecordEdit_View.Data_Prev_ButtonClick( Sender : TObject );
begin
  Current := Current - 1; // prev record
end;

procedure TRecordEdit_View.Data_Save_ButtonClick( Sender : TObject );
begin
  SaveData;
end;

procedure TRecordEdit_View.FormCreate( Sender : TObject );
begin
  InitData;
end;

procedure TRecordEdit_View.InitData;
begin
  FCurrent := Low( FData ); // first record
  LoadCurrent;              // load data from record
end;

procedure TRecordEdit_View.LoadCurrent;
begin
  // Data from record to controls
  Data_Firstname_Edit.Text := FData[Current].Firstname;
  Data_Lastname_Edit.Text  := FData[Current].Lastname;
  // Update the Current-Edit
  Current_Edit.Text := IntToStr( Current );
end;

procedure TRecordEdit_View.SaveData;
begin
  ShowMessage( 'Needs to be implemented!' );
end;

procedure TRecordEdit_View.SetCurrent( const Value : Integer );
begin
  // check, if we have a change and if we can change to the new index
  if ( Value <> Current ) and ( Value >= Low( FData ) ) and ( Value <= High( FData ) )
  then
    begin
      StoreCurrent;      // store data from controls
      FCurrent := Value; // change current index
      LoadCurrent;       // load data from record
    end;
end;

procedure TRecordEdit_View.StoreCurrent;
begin
  // Data from controls to record
  FData[Current].Firstname := Data_Firstname_Edit.Text;
  FData[Current].Lastname  := Data_Lastname_Edit.Text;
end;

end.

和形式

object RecordEdit_View: TRecordEdit_View
  Left = 0
  Top = 0
  Caption = 'RecordEdit_View'
  ClientHeight = 337
  ClientWidth = 635
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'Tahoma'
  Font.Style = []
  OldCreateOrder = False
  OnCreate = FormCreate
  PixelsPerInch = 96
  TextHeight = 13
  object Current_Edit: TEdit
    Left = 107
    Top = 16
    Width = 75
    Height = 21
    TabOrder = 0
    Text = 'Current_Edit'
    OnChange = Current_EditChange
  end
  object Data_Firstname_Edit: TEdit
    Left = 80
    Top = 56
    Width = 129
    Height = 21
    MaxLength = 50
    TabOrder = 1
    Text = 'Data_Firstname_Edit'
  end
  object Data_Lastname_Edit: TEdit
    Left = 80
    Top = 83
    Width = 129
    Height = 21
    MaxLength = 50
    TabOrder = 2
    Text = 'Data_Lastname_Edit'
  end
  object Data_Prev_Button: TButton
    Left = 80
    Top = 16
    Width = 21
    Height = 21
    Caption = '<'
    TabOrder = 3
    OnClick = Data_Prev_ButtonClick
  end
  object Data_Next_Button: TButton
    Left = 188
    Top = 16
    Width = 21
    Height = 21
    Caption = '>'
    TabOrder = 4
    OnClick = Data_Next_ButtonClick
  end
  object Data_Save_Button: TButton
    Left = 80
    Top = 118
    Width = 129
    Height = 25
    Caption = 'Save Data'
    TabOrder = 5
    OnClick = Data_Save_ButtonClick
  end
end

您可以在此处获取完整的源代码和可执行文件

于 2012-11-07T01:13:00.110 回答