Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delphi 7 edit component creation

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.

like image 225
ltsstar Avatar asked Jun 18 '26 06:06

ltsstar


1 Answers

There's a margin around the text in TEdit control, so if you set the Font.Height to 48, the height of the control won't be exactly 48 if the control has the AutoSize property set to True. I would personally decrease height of the font, and for being sure turn the AutoSize off. Your CreateZeichen method would then look like this:

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;
like image 194
TLama Avatar answered Jun 19 '26 21:06

TLama