# From a Delphi VCL OnClick to the Machine Code

> Follow an OnClick binding from a binary DFM to the Delphi method table and x86 instructions. Reproduce the analysis with the same executable and source.

Canonical HTML: <https://www.de-decompiler.com/de-decompiler-vcl-event-handler>

What does the Show details button do in a Delphi executable? The DFM resource names the handler, the class metadata gives its address, and the instructions show which control it updates. This analysis follows all three in the same Win32 Photo Catalog executable built with Delphi 13.

[Download Photo Catalog (two EXEs, Delphi source and verification script)](https://www.de-decompiler.com/files/vcl-photo-catalog-analysis.zip)

Start with VclPhotoCatalog.exe. Verify its SHA-256 against SHA256SUMS.txt. The archive also contains a renamed copy for the last part of the analysis and the original source for checking the result. All findings below come from static inspection.

## 1. Identify the event in the binary DFM

In DE Decompiler 26.7, open TfrmPhotoCatalog under Forms, choose Designer (read only) and select Show details. The event row leads to btnShowDetailsClick. Open the DFM tab to verify the relationship independently of the preview. The form defines a TButton with an OnClick value and a separate TLabel whose initial caption is Ready.

The same form is in the PE resource directory as type RT_RCDATA (10), name TFRMPHOTOCATALOG. The resource starts with TPF0 at RVA 0x002575C4. This is component-stream data. The OnClick value is a method name encoded in the stream, so resolving it to code requires the class metadata.

![The event shown in the read-only designer.](https://www.de-decompiler.com/image/analysis-examples/demo-vcl-event.png)

```pascal
object lblStatus: TLabel
  Caption = 'Ready'
end
object btnShowDetails: TButton
  Caption = 'Show details'
  OnClick = btnShowDetailsClick
end
```

## 2. Resolve the method name to an x86 address

Double-click the value in the event row to open the handler. To check the address from the binary, locate the class virtual method table at VA 0x005FB71C. Its method-table pointer (VMT − 0x40 in this build) gives VA 0x005FBA3A. The table contains one classic method record. At VA 0x005FBA3C, the first two bytes give the record length (0x1A), the next four give the address (FC BA 5F 00 in little-endian order), and byte 0x13 precedes the name btnShowDetailsClick.

The resulting preferred image address is 0x005FBAFC. Subtract the PE image base, 0x00400000, to get RVA 0x001FBAFC. The section layout maps it to file offset 0x001FAEFC. Record the RVA when comparing tools because a rebased project can display a different virtual address for the same byte.

![The handler opened from the form event in DE Decompiler 26.7.](https://www.de-decompiler.com/image/analysis-examples/demo-vcl-handler.png)

## 3. Identify the two inputs to the call

At entry, EAX holds the form instance (Self) under the Delphi Win32 register calling convention. The first instruction replaces it with the object reference from Self + 0x460. The form’s field table identifies offset 0x460 as lblStatus and offset 0x464 as btnShowDetails. The button triggers the method, while the label is the receiver of the call.

The next instruction loads EDX with 0x005FBB1C. Following that pointer to the UnicodeString literal yields Two landscape illustrations in the catalog. Its header contains an element size of 2, a reference count of −1 and a length of 43 UTF-16 code units. An ASCII search alone can miss the string because it is stored as UTF-16LE.

The direct CALL at 0x005FBB07 goes to 0x00544698. The published Caption property in the TLabel RTTI has this same setter address. Together, the field offset, string argument and property metadata account for the Pascal assignment shown by DE Decompiler.

```asm
005FBAFC  8B 80 60 04 00 00  mov eax, [eax+460h]
005FBB02  BA 1C BB 5F 00     mov edx, 005FBB1Ch
005FBB07  E8 8C 8B F4 FF     call 00544698h
005FBB0C  C3                 ret
```

## 4. Check the recovered statement against the source

The statement corresponds to the handler in fmPhotoCatalog.pas. The recovered listing may include the explicit Self prefix and an instruction-address label. Qualifying lblStatus with Self is equivalent here. In this build, the handler contains one direct call and returns. There is no branch in the handler. The called setter has its own code, so the four instructions establish the assignment without describing all the work the VCL performs inside the setter.

The evidence shows a label update tied to the button’s design-time event. When analyzing an unfamiliar executable, other runtime assignments to the event or a different code path inside the called method would require separate checks.

```pascal
procedure TfrmPhotoCatalog.btnShowDetailsClick(Sender: TObject);
begin
  lblStatus.Caption := 'Two landscape illustrations in the catalog.';
end;
```

## 5. Repeat the trace after the metadata names change

Open VclPhotoCatalog-obfuscated.exe from the same archive and locate the form by its visible caption. On that copy, the DFM binds the button i0000000000000 to b000000000000000000, and the classic method table contains the same renamed handler. Its entry is still RVA 0x001FBAFC.

The 17 machine-code bytes of the handler match byte for byte, the load still uses Self + 0x460, and the literal is unchanged. The field at that offset is now named h00000000. This comparison shows which conclusions survive the rename. The original identifiers come from the unmodified file; the field offset, call target and new caption can also be verified in the renamed copy.

## Address checklist for the original EXE

- RT_RCDATA — RVA 0x002575C4 (file 0x0024A1C4)

- TfrmPhotoCatalog VMT — VA 0x005FB71C

- vmtMethodTable — VA 0x005FBA3A

- btnShowDetailsClick — VA 0x005FBAFC / RVA 0x001FBAFC (file 0x001FAEFC)

- lblStatus / btnShowDetails — Self + 0x460 / Self + 0x464

- UnicodeString — VA 0x005FBB1C (43 UTF-16 code units)

- Caption setter — VA 0x00544698

[Open the Photo Catalog analysis example](https://www.de-decompiler.com/analysis-examples#vcl-event)

## Delphi format and calling-convention references

- [Embarcadero · Internal Data Formats](https://docwiki.embarcadero.com/RADStudio/Florence/en/Internal_Data_Formats_(Delphi))

- [Embarcadero · Delphi Calling Conventions](https://docwiki.embarcadero.com/RADStudio/Florence/en/Program_Control)

- [Embarcadero · TReader](https://docwiki.embarcadero.com/Libraries/Florence/en/System.Classes.TReader)

© Sergey Chubchenko, lead developer of DE Decompiler
