# Introducing TUIState.DesignUrl, DesignPreload, DesignedComponent

**URL:** https://forum.castle-engine.io/t/introducing-tuistate-designurl-designpreload-designedcomponent/326
**Category:** News
**Created:** [May 1, 2021, 12:55am UTC](https://forum.castle-engine.io/t/introducing-tuistate-designurl-designpreload-designedcomponent/326 "2021-05-01T00:55:13Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![michalis](https://forum.castle-engine.io/user_avatar/forum.castle-engine.io/michalis/32/3_2.png) [@michalis](https://forum.castle-engine.io/u/michalis)
#### Post date: [May 1, 2021, 12:55am UTC](https://forum.castle-engine.io/t/introducing-tuistate-designurl-designpreload-designedcomponent/326/1 "2021-05-01T00:55:14Z")

</div>

| [![Zrzut ekranu z 2021-05-01 02-52-51](https://castle-engine.io/wp/wp-content/uploads/2021/05/Zrzut-ekranu-z-2021-05-01-02-52-51-200x117.png)](https://castle-engine.io/wp/wp-content/uploads/2021/05/Zrzut-ekranu-z-2021-05-01-02-52-51.png "Zrzut ekranu z 2021-05-01 02-52-51") |

We expose [TUIState.DesignUrl](https://castle-engine.io/apidoc-unstable/html/CastleUIState.TUIState.html#DesignUrl) (and some friends) as a more comfortable alternative to the [TUIState.InsertUserInterface](https://castle-engine.io/apidoc-unstable/html/CastleUIState.TUIState.html#InsertUserInterface) method. `InsertUserInterface` was a method used by many CGE applications to load a designed UI into a TUIState. Advantages of the new `TUIState.DesignUrl` approach:

1. It looks simpler. You do not need to think about `UiOwner` and `FreeAtStop` parameters passed to `InsertUserInterface`. You have `TUIState.DesignedComponent` to replace previous `UiOwner.FindRequiredComponent`.

2. It allows to trivially use new [DesignPreload](https://castle-engine.io/apidoc-unstable/html/CastleUIState.TUIState.html#DesignPreload) property, a powerful way to load state data in the constructor (instead of at start), which is sometimes desirable — this way state can later start instantly, albeit at the cost of longer application initialization time and larger memory usage (e.g. textures and images used by state are preloaded in memory).

All of CGE examples and templates have been adjusted to use the new approach.

Previous code looked like this:

```
procedure TStateMenu.Start;
var
  UiOwner: TComponent;
begin
  inherited;

{ Load designed user interface }  
InsertUserInterface(‘castle-data:/gamestatemenu.castle-user-interface’, FreeAtStop, UiOwner);

{ Find components, by name, that we need to access from code }  
MyButton := UiOwner.FindRequiredComponent(‘MyButton’) as TCastleButton;  
end;
```

New code looks like this:

```
constructor TStateMenu.Create(AOwner: TComponent);
begin
  inherited;
  DesignUrl := 'castle-data:/gamestatemenu.castle-user-interface';
  // DesignPreload := true; // use this to preload design in constructor
end;

procedure TStateMenu.Start;  
begin  
inherited;

{ Find components, by name, that we need to access from code }  
MyButton := DesignedComponent(‘MyButton’) as TCastleButton;  
end;
```
