3

I have a problem according to run-time creation of edit components in Delphi 7. So when I create TEdit components after the program ran for "some" time it perfectly works. However, when I create TEdit elements at the Forms OnCreate event, they have a wrong height. Furthermore the (almost) simultaneously created Shapes have the right height.

The red marked Edits are created in the Forms OnCreate procedure, while the others are created on another event.

Edit:

procedure TTPLVisorForm.CreateZeichen(ZShape : TShape; ZEdit : TEdit; VLeft : integer);
begin
  with ZShape do
  begin
    Width := 50;
    Height := 50;
    Left := VLeft;
    Top := 25;
    Shape := stRectangle;
    Parent := self.Band;
    SendToBack();
  end;

  with ZEdit do
  begin
    Text := '#';
    Left := VLeft+1;
    Top := 26;
    Parent := self.Band;
    Font.Height := 48;
    Width := 48;
    Height := 48;
    SendToBack;
  end;
end;

Getting called by:

procedure TZeichen.Anzeigen(Form : TObject; Left : integer);
begin
  self.Form := Form;

  self.ZShape := TShape.Create(TTPLVisorForm(self.Form).Band);
  self.ZEdit := TEdit.Create(TTPLVisorForm(self.Form).Band);

  TTPLVisorForm(Form).CreateZeichen(self.ZShape, self.ZEdit, Left);
end;

Getting called by:

procedure TMagnetband.ErweitereRechts;
var
  Zeichen : TZeichenKette;
begin
  Zeichen := TZeichenKette.Create;
  self.LetztesZeichen.Naechstes := TZeichenKette(Zeichen);
  Zeichen.Vorheriges := self.LetztesZeichen;

  Zeichen.Zeichen.Anzeigen(self.Form,
                                      self.LetztesZeichen.Zeichen.ZShape.Left +
                                      self.LetztesZeichen.Zeichen.ZShape.Width +
                                      self.Padding);
  self.LetztesZeichen := Zeichen;
  self.Laenge := self.Laenge+1;
end;

Getting again called by:

procedure TTuringmaschine.ZeichenAnfuegen;
begin
  self.Magnetband.ErweitereRechts;
end;

Getting called by:

procedure TTuringmaschine.PanelResize(Sender: TObject);
begin
  while self.Magnetband.GetRechtsMax < self.Panel.Width do
    self.ZeichenAnfuegen;
end;

Finally gets called by:

Constructor TTuringmaschine.Create(Form : TObject);
var
  Breite : integer;
begin
  self.Zustand := 0;
  self.Form := TTPLVisorForm(Form);
  self.Panel := TTPLVisorForm(self.Form).Band;
  self.Magnetband := TMagnetband.Create(self.Form);
  TTPLVisorForm(Form).Band.OnResize := self.PanelResize;

  self.PanelResize(Nil);
  //self.CreateMagnetkopf;
end;

And the Constructor is either called at the OnCreate event or on another event.

4

1 回答 1

5

控件中的文本周围有一个边距TEdit,因此如果将 设置为 48,如果控件的属性设置为 True Font.Height,则控件的高度不会正好为 48 。AutoSize我会亲自降低字体的高度,并确保AutoSize关闭。您的CreateZeichen方法将如下所示:

procedure TTPLVisorForm.CreateZeichen(ZShape: TShape; ZEdit: TEdit;
  VLeft: Integer);
begin
  with ZShape do
  begin
    Width := 50;
    Height := 50;
    Left := VLeft;
    Top := 25;
    Shape := stRectangle;
    Parent := Self.Band;
    SendToBack;
  end;

  with ZEdit do
  begin
    AutoSize := False;
    Text := '#';
    Left := VLeft + 1;
    Top := 26;
    Parent := Self.Band;
    Font.Height := 40;
    Width := 48;
    Height := 48;
    SendToBack;
  end;
end;
于 2013-05-05T15:37:16.073 回答