Root > How to... > ...convert the call stack to text or string?

...convert the call stack to text or string?

Previous pageReturn to chapter overviewNext page   

Option 1

Use the StackTrace property of an exception object (Delphi 2009+):

 

except
  on E: Exception do
    Memo1.Lines.Text := E.StackTrace;
end;

 

 

Option 2

Use the ToString method to convert call stack to single string with default formatting:

 

var
  CallStack: TEurekaBaseStackList;
begin
  CallStack := { ... somehow retrieve call stack ... };
  Memo1.Lines.Text := CallStack.ToString;
end;

 

 

Option 3

Use the Assign method to convert call stack to TStrings object with default formatting:

 

var
  CallStack: TEurekaBaseStackList;
begin
  CallStack := { ... somehow retrieve call stack ... };
  Memo1.Lines.Assign(CallStack);
end;

 

 

Option 4

Use the CallStackToString function from ECallStack unit:

 

// (CallStackToString function allows you to override header and formatting)
 
var
  CallStack: TEurekaBaseStackList;
  Formatter: TCompactStackFormatter;
begin
  CallStack := { ... somehow retrieve call stack ... };
 
  // A): Default formatting and header:
  Memo1.Lines.Text := CallStackToString(CallStack);
 
  // B): With custom header:
  Memo1.Lines.Text := CallStackToString(CallStack, 'Error Details:');
 
  // C): Custom formatting:
  Formatter := TCompactStackFormatter.Create;
  try
    // <- here you can customize Formatter (for example: alter captions for columns, etc.)
    Memo1.Lines.Text := CallStackToString(CallStack, '', Formatter);
  finally
    FreeAndNil(Formatter);
  end;
end;

 

See below for examples of various formatters.

 

 

Option 5

Use CallStackToStrings function from ECallStack unit:

 

// (CallStackToStrings function allows you to override header and formatting)
 
var
  CallStack: TEurekaBaseStackList;
  Formatter: TCompactStackFormatter;
begin
  CallStack := { ... somehow retrieve call stack ... };
 
  // A): Default formatting and header:
  CallStackToStrings(CallStack, Memo1.Lines);
 
  // B): With custom header:
  CallStackToStrings(CallStack, Memo1.Lines, 'Error Details:');
 
  // C): Custom formatting:
  Formatter := TCompactStackFormatter.Create;
  try
    // <- here you can customize Formatter (for example: alter captions for columns, etc.)
    CallStackToStrings(CallStack, Memo1.Lines, '', Formatter);
  finally
    FreeAndNil(Formatter);
  end;
end;

 

See below for examples of various formatters.

 

 

Available formatters

EurekaLog has 4 built-in formatters:

 

TEurekaStackFormatter - general formatter for EurekaLog-style call stack (i.e. fixed-width table with columns) - best to be used in text files:

---------------------------------------------------------------------------------------------------------------------------------

|Methods |Details|Stack   |Address |Module        |Offset  |Source          |Unit        |Class        |Procedure/Method|Line   |

---------------------------------------------------------------------------------------------------------------------------------

|*Exception Thread: ID=9672; Parent=0; Priority=0                                                                               |

|Class=; Name=MAIN                                                                                                              |

|DeadLock=0; Wait Chain=                                                                                                        |

|Comment=                                                                                                                       |

|-------------------------------------------------------------------------------------------------------------------------------|

|7FFFFFFE|04     |00000000|007CD41D|Project183.exe|0048D41D|Unit1.pas       |Unit1       |TForm1       |Button1Click    |37[1]  |

|00000060|04     |019DF02C|006F5043|Project183.exe|003B5043|Vcl.Controls.pas|Vcl.Controls|TControl     |Click           |7707[9]|

|00000020|04     |019DF038|00710176|Project183.exe|003D0176|Vcl.StdCtrls.pas|Vcl.StdCtrls|TCustomButton|Click           |5953[3]|

...

 

TEurekaStackFormatterV6 - backward-compatibility formatter to produce call stack in EurekaLog V6 format (less columns)

-----------------------------------------------------------------------------

|Address |Module        |Unit        |Class        |Procedure/Method|Line   |

-----------------------------------------------------------------------------

|*Exception Thread: ID=10640; Parent=0; Priority=0                          |

|Class=; Name=MAIN                                                          |

|DeadLock=0; Wait Chain=                                                    |

|Comment=                                                                   |

|---------------------------------------------------------------------------|

|00B3D41D|Project183.exe|Unit1       |TForm1       |Button1Click    |37[1]  |

|00A65043|Project183.exe|Vcl.Controls|TControl     |Click           |7707[9]|

|00A80176|Project183.exe|Vcl.StdCtrls|TCustomButton|Click           |5953[3]|

...

 

TSimpleStackFormatter - produces list-like view of call stack (no columns) suitable for variable-width fonts (best to be used in message boxes)

(0048D41D){Project183.exe} [007FD41D] Unit1.TForm1.Button1Click (Line 37, "Unit1.pas") + $11

(003B5043){Project183.exe} [00725043] Vcl.Controls.TControl.Click (Line 7707, "Vcl.Controls.pas") + $8

(003D0176){Project183.exe} [00740176] Vcl.StdCtrls.TCustomButton.Click (Line 5953, "Vcl.StdCtrls.pas") + $2

...

 

TCompactStackFormatter - similar to TSimpleStackFormatter, but produces more compact output with less details (good for quick preview)

[0132D41D] Unit1.TForm1.Button1Click (Line 37, "Unit1.pas")

[01255043] Vcl.Controls.TControl.Click (Line 7707, "Vcl.Controls.pas")

[01270176] Vcl.StdCtrls.TCustomButton.Click (Line 5953, "Vcl.StdCtrls.pas")

...

 

 

See also:




Send feedback... Build date: 2025-11-08
Last edited: 2025-10-13
PRIVACY STATEMENT
The documentation team uses the feedback submitted to improve the EurekaLog documentation. We do not use your e-mail address for any other purpose. We will remove your e-mail address from our system after the issue you are reporting has been resolved. While we are working to resolve this issue, we may send you an e-mail message to request more information about your feedback. After the issues have been addressed, we may send you an email message to let you know that your feedback has been addressed.


Permanent link to this article: https://www.eurekalog.com/help/eurekalog/how_to_convert_call_stack_to_text.php