WebExeBuilder Documentation

getStyle

Category: Style Management

Namespace: web.styles.getStyle

Description

Gets the currently active VCL style name. VCL styles control the visual appearance of the application window and controls.

Syntax

const styleName = await web.styles.getStyle();

Parameters

None

Returns

Promise<string> - Returns a promise that resolves with the name of the currently active style

Examples

Simple example

const currentStyle = await web.styles.getStyle();
console.log('Current style:', currentStyle);
// Output: "Windows10"

Check current theme

const style = await web.styles.getStyle();

if (style === 'Windows10') {
    console.log('Using light theme');
} else if (style.includes('Dark')) {
    console.log('Using dark theme');
}

Save user preference

// Save current style to registry for next session
const currentStyle = await web.styles.getStyle();

await web.registry.writeValue({
    keyPath: 'Software\\MyApp\\Settings',
    valueName: 'PreferredStyle',
    value: currentStyle
});

console.log('Style preference saved:', currentStyle);

Detect style changes (polling)

// Since there are no change events, poll to detect style changes
let lastStyle = await web.styles.getStyle();

setInterval(async () => {
    const currentStyle = await web.styles.getStyle();
    
    if (currentStyle !== lastStyle) {
        console.log('Style changed from', lastStyle, 'to', currentStyle);
        lastStyle = currentStyle;
        
        // Update UI or perform other actions
        updateThemeUI(currentStyle);
    }
}, 1000); // Check every second

Use Cases

  • Get the current application theme/style
  • Save user's style preference
  • Display current theme in settings UI
  • Check which style is active before making changes
  • Implement theme-aware features

Notes

  • Returns the name of the active VCL style (e.g., "Windows10", "Glow", "Amakrits")
  • Style names are case-sensitive (e.g., "Windows" not "windows")
  • Returns empty string ("") only if there's an error or the style system is unavailable
  • Default style is typically "Windows" if no custom style is applied
  • The returned string exactly matches Delphi's TStyleManager.ActiveStyle.Name property
  • Styles must be embedded in the application at compile time
  • Available styles are determined by the WebExeBuilder project settings
  • No change events: There is no automatic notification when the style changes - use setInterval() if you need to detect changes
  • Backend retrieves this synchronously from TStyleManager, but JavaScript API wraps it in a Promise for consistency