Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
744 views
in Technique[技术] by (71.8m points)

object - Delphi - Rich edit doesn't show on dynamically created form

I've dynamically created a Form in my program, and it works and shows perfectly, but the RichEdit I've also dynamically created doesn't want to show on the Form at all. How can I show the RichEdit on the Form?

Code I'm using:

procedure TfrmPuntehou.lblAbbClick(Sender: TObject);
var
  frmAbb: TForm;
  redAbbreviations: TRichEdit;
begin
  //opens abbreviations
  frmAbb := TForm.Create(nil);
  redAbbreviations := TRichEdit.Create(nil);
  try
    with frmAbb do
    begin
      Width := 400;
      Height := 400;
      Caption := 'Abbreviations';
      Position := poOwnerFormCenter;
      ShowModal;
    end;
    with redAbbreviations do
    begin
      Parent := frmAbb;
      Width := 300;
      Height := 353;
      redAbbreviations.Paragraph.TabCount := 2;
      redAbbreviations.Paragraph.Tab[0] := 30;
      redAbbreviations.Paragraph.Tab[1] := 60;
      Lines.Add('DEV'+#9+'='+#9+'SWD Development');
      Lines.Add('1660'+#9+'='+#9+'1660s');
      Lines.Add('2.1'+#9+'='+#9+'2.1s');
      Lines.Add('MIN'+#9+'='+#9+'Minis');
      Lines.Add('SR'+#9+'='+#9+'Stockrods');
      Lines.Add('PR'+#9+'='+#9+'Pinkrods');
      Lines.Add('HR'+#9+'='+#9+'Hotrods');
      Lines.Add('HM'+#9+'='+#9+'Heavy Metals');
      Lines.Add('V8'+#9+'='+#9+'V8s');
      Lines.Add('MA'+#9+'='+#9+'Midgets A');
      Lines.Add('MB'+#9+'='+#9+'Midgets B');
      Lines.Add('SP'+#9+'='+#9+'Sprints');
      Lines.Add('CRO'+#9+'='+#9+'Crosskarts');
      Lines.Add('LM'+#9+'='+#9+'Late Models');
      Font.Size := 13;
    end;
  finally
    frmAbb.Free;
  end;
end;
question from:https://stackoverflow.com/questions/65879923/delphi-rich-edit-doesnt-show-on-dynamically-created-form

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Move the ShowModal from the initialization part of the frmAbb to the end of the code, just before the finally statement.

procedure TForm1.Button1Click(Sender: TObject);
var
  frmAbb: TForm;
  redAbbreviations: TRichEdit;
begin
  //opens abbreviations
  frmAbb := TForm.Create(nil);
  try
    redAbbreviations := TRichEdit.Create(frmAbb);
    with frmAbb do
    begin
      Width := 400;
      Height := 400;
      Caption := 'Abbreviations';
      Position := poOwnerFormCenter;
    end;
    with redAbbreviations do
    begin
      Parent := frmAbb;
      Width := 300;
      Height := 353;
      redAbbreviations.Paragraph.TabCount := 2;
      redAbbreviations.Paragraph.Tab[0] := 30;
      redAbbreviations.Paragraph.Tab[1] := 60;
      Lines.Add('DEV'+#9+'='+#9+'SWD Development');
      Lines.Add('1660'+#9+'='+#9+'1660s');
      Lines.Add('2.1'+#9+'='+#9+'2.1s');
      Lines.Add('MIN'+#9+'='+#9+'Minis');
      Lines.Add('SR'+#9+'='+#9+'Stockrods');
      Lines.Add('PR'+#9+'='+#9+'Pinkrods');
      Lines.Add('HR'+#9+'='+#9+'Hotrods');
      Lines.Add('HM'+#9+'='+#9+'Heavy Metals');
      Lines.Add('V8'+#9+'='+#9+'V8s');
      Lines.Add('MA'+#9+'='+#9+'Midgets A');
      Lines.Add('MB'+#9+'='+#9+'Midgets B');
      Lines.Add('SP'+#9+'='+#9+'Sprints');
      Lines.Add('CRO'+#9+'='+#9+'Crosskarts');
      Lines.Add('LM'+#9+'='+#9+'Late Models');
      Font.Size := 13;
    end;
    frmAbb.ShowModal;
  finally
    frmAbb.Free;
  end;
end;

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...