Ad Space — Top Banner

EWriteError

Delphi Programming Language

Severity: Moderate

What Does This Error Mean?

EWriteError is raised when Delphi cannot write a component property to a stream or DFM file. This subclass of EFilerError occurs when a component's property value cannot be serialized — for example, a property with a type that cannot be converted to a text or binary stream. It can also happen when the stream itself is read-only or the disk is full.

Affected Models

  • Delphi 10.4 Sydney
  • Delphi 11 Alexandria
  • Delphi 12 Athens
  • Embarcadero RAD Studio
  • Free Pascal / Lazarus

Common Causes

  • A published component property has a type that the streaming system cannot serialize
  • Attempting to write to a read-only stream or a file opened without write permission
  • Disk is full or the target path does not exist when saving a component to a file
  • A property getter raises an exception during streaming, which is wrapped as EWriteError
  • Writing a component whose sub-component is not properly owned or registered

How to Fix It

  1. Read the exception message to identify which component and property caused the write failure. The message format is typically 'Error writing ClassName.PropertyName: reason'.

    If EWriteError fires when saving a form in the IDE, the IDE Output panel may show additional details.

  2. Check if the property's getter raises an exception. During streaming, Delphi calls the getter to obtain the value to write. If the getter raises an exception, it becomes EWriteError.

    Property getters must always return a valid value safely — they should never raise exceptions.

  3. For a file-based write error, check that the target directory exists and the application has write permission. Use FileExists and DirectoryExists checks before writing.

    On Windows, the application's own folder may not be writable if installed in Program Files. Write to the AppData folder instead.

  4. If a custom component property should not be streamed, mark it as non-published or use the stored keyword: property MyProp: Integer read FProp write FProp stored False; — Delphi will not attempt to stream it.

    stored False tells the streaming system to skip this property entirely when writing.

  5. Wrap streaming code that saves user data in try/except to catch EWriteError and show a meaningful error message rather than crashing.

    Always give the user a chance to save to a different location if the original location fails.

When to Call a Professional

EWriteError during form saving means a property cannot be serialized. Check the exception message for the component and property name. For custom components, ensure all published properties have proper read/write methods and return valid, serializable values. Avoid raising exceptions inside property getters — the streaming system calls them during save.

Frequently Asked Questions

Can I make the streaming system ignore a property that causes EWriteError?

Yes. Mark the property with stored False to prevent the streamer from attempting to write it. Alternatively, use DefineProperties to provide a custom read/write implementation that handles edge cases gracefully. If the property must be streamed, fix the getter so it never raises an exception.

Why does EWriteError happen in the IDE when I save my form?

The IDE saves the form by streaming all component properties to the DFM file. If a published property raises an exception in its getter, or has a value the streaming system cannot convert to text, the IDE raises EWriteError. Check for custom components on the form that might have buggy property getters.

Is EWriteError always about disk writes?

No. EWriteError applies to any TStream — not just files. It can be raised when writing to a TMemoryStream, TStringStream, a network stream, or any other stream implementation. The name 'write error' refers to the streaming operation, not necessarily a disk file write.