Does anyone has a trick for quickly put in clipboard the content of a string variable while debugging ? Variable inspection is great, but string must be processed as it's displayed quoted and with #$D#$A instead of linebreaks .... Ty
type TForm10 = class(TForm) Button1: TButton; procedure Button1Click(Sender: TObject); private FClipStr: String; public { Public declarations } public function CopyToClipboardForDebugging: Boolean; end;
var Form10: TForm10;
implementation
{$R *.dfm}
function TForm10.CopyToClipboardForDebugging: Boolean; begin Result := TRUE;
Clipboard.AsText := FClipStr; end;
procedure TForm10.Button1Click(Sender: TObject); begin FClipStr := 'Test';
FClipStr := 'Another Test'; end;
-----
CopyToClipboardForDebugging needs to be declared public otherwise it will be eliminated by the linker.
Add a watch on CopyToClipboardForDebugging (make sure you select "Allow side effects and function calls") FClipStr will be copied to the clipboard while stepping through your code.
+Lars Fosdal Well, it looks like the OP is asking for this to make looking at the contents of string variables easier to read while debugging. A replacement debug visualizer could solve the same problem without needing to mess about with the clipboard or add extra unnecessary code to the project.
My typical usage for that is SQL queries ... I quickly made a macro in Notepad++ to convert 'Delphi' string to normal string, but it would be great to have a mean to have it directly ....
Jamie Oliver - - You can try something like this:
ReplyDeletetype
TForm10 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
FClipStr: String;
public
{ Public declarations }
public
function CopyToClipboardForDebugging: Boolean;
end;
var
Form10: TForm10;
implementation
{$R *.dfm}
function TForm10.CopyToClipboardForDebugging: Boolean;
begin
Result := TRUE;
Clipboard.AsText := FClipStr;
end;
procedure TForm10.Button1Click(Sender: TObject);
begin
FClipStr := 'Test';
FClipStr := 'Another Test';
end;
-----
CopyToClipboardForDebugging needs to be declared public otherwise it will be eliminated by the linker.
Add a watch on CopyToClipboardForDebugging (make sure you select "Allow side effects and function calls") FClipStr will be copied to the clipboard while stepping through your code.
Oh nice idea, I wouldn't have think to use clipboard directly in code ! Thank you Paul Thornton !
ReplyDeleteThat's a nice tip!
ReplyDeleteIs it possible to write a debugger visualizer for strings?
ReplyDeleteHow do you mean, Anthony Frazier
ReplyDelete+Lars Fosdal Well, it looks like the OP is asking for this to make looking at the contents of string variables easier to read while debugging. A replacement debug visualizer could solve the same problem without needing to mess about with the clipboard or add extra unnecessary code to the project.
ReplyDeleteMy typical usage for that is SQL queries ... I quickly made a macro in Notepad++ to convert 'Delphi' string to normal string, but it would be great to have a mean to have it directly ....
ReplyDelete