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 StackTrace property of exception object (Delphi 2009+):

 

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

 

 

Option 2

Use 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 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 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;

 

Available formatters are:

TEurekaStackFormatter - general formatter for EurekaLog-style call stack (i.e. fixed-width table with columns) - best to be used in text files
TEurekaStackFormatterV6 - backward-compatibility formatter to produce call stack in EurekaLog V6 format (less columns)
TSimpleStackFormatter - produces list-like view of call stack (no columns) suitable for variable-width fonts (best to be used in message boxes)
TCompactStackFormatter - similar to TSimpleStackFormatter, but produces more compact output with less details (good for quick preview)

 

 

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;

 

Available formatters are:

TEurekaStackFormatter - general formatter for EurekaLog-style call stack (i.e. fixed-width table with columns) - best to be used in text files
TEurekaStackFormatterV6 - backward-compatibility formatter to produce call stack in EurekaLog V6 format (less columns)
TSimpleStackFormatter - produces list-like view of call stack (no columns) suitable for variable-width fonts (best to be used in message boxes)
TCompactStackFormatter - similar to TSimpleStackFormatter, but produces more compact output with less details (good for quick preview)

 

 

See also:




Send feedback... Build date: 2018-11-26
Last edited: 2018-10-29
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