Racing condition sync creating forms

On my way to "asyncawaitify" my app, I now create my forms like this:

  I := 1;
  TermsForm     := TTermsForm    .CreateNew('Container'+IntToStr(I),nil); Inc(I);
  DoclistForm   := TDoclistForm  .CreateNew('Container'+IntToStr(I),nil); Inc(I);
  LoginForm     := TLoginForm    .CreateNew('Container'+IntToStr(I),nil); Inc(I);
  ImprintForm   := TImprintForm  .CreateNew('Container'+IntToStr(I),nil); Inc(I);
  DataProtForm  := TDataProtForm .CreateNew('Container'+IntToStr(I),nil); Inc(I);
  ShowPDFForm   := TShowPDFForm  .CreateNew('Container'+IntToStr(I),nil); Inc(I);
  MenuForm      := TMenuForm     .CreateNew('Container'+IntToStr(I),nil); Inc(I);
  SelectDocForm := TSelectDocForm.CreateNew('Container'+IntToStr(I),nil); Inc(I);
  ContactForm   := TContactForm  .CreateNew('Container'+IntToStr(I),nil); Inc(I);
  LocationsForm := TLocationsForm.CreateNew('Container'+IntToStr(I),nil); Inc(I);

  Await(TTermsForm    ,TermsForm    .Load()); Await(Sleep(20));
  Await(TDoclistForm  ,DoclistForm  .Load()); Await(Sleep(20));
  Await(TLoginForm    ,LoginForm    .Load()); Await(Sleep(20));
  Await(TImprintForm  ,ImprintForm  .Load()); Await(Sleep(20));
  Await(TDataProtForm ,DataProtForm .Load()); Await(Sleep(20));
  Await(TShowPDFForm  ,ShowPDFForm  .Load()); Await(Sleep(20));
  Await(TMenuForm     ,MenuForm     .Load()); Await(Sleep(20));
  Await(TSelectDocForm,SelectDocForm.Load()); Await(Sleep(20));
  Await(TContactForm  ,ContactForm  .Load()); Await(Sleep(20));
  Await(TLocationsForm,LocationsForm.Load()); Await(Sleep(20));

When I do NOT sleep some msecs after each form load, the rendered HTML is totally scrambled, read, HTMLs of different forms are mixed together or show up 2 or 3 times, such that I get warnings in the console because of double or tripple IDs..

Now, while in principal I could live with the sleeps, it leaves a bad taste and maybe points to a larger problem. Would be great if you would investigate the cause of this.

Thanks a lot,


That's interesting. I create forms as needed, but it is worth being aware of that.