mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-16 16:12:57 +02:00
synedit: improve synedit copy to clipboard error handling (more informative), simplify code (by Alexander S. Klenin, mantis #0011548)
git-svn-id: trunk@18106 -
This commit is contained in:
parent
e3b2307040
commit
b24b71e52a
@ -1296,23 +1296,19 @@ var
|
||||
SLen: integer;
|
||||
Failed: boolean;
|
||||
begin
|
||||
if SText <> '' then begin
|
||||
Failed := TRUE; // assume the worst.
|
||||
if SText = '' then exit;
|
||||
SLen := Length(SText);
|
||||
{$IFDEF SYN_LAZARUS}
|
||||
try
|
||||
Clipboard.Clear;
|
||||
Clipboard.AsText:=SText;
|
||||
Failed:=not Clipboard.HasFormat(CF_TEXT);
|
||||
except
|
||||
end;
|
||||
if not Failed then begin
|
||||
Failed:=true;
|
||||
if not Clipboard.HasFormat(CF_TEXT) then
|
||||
raise ESynEditError.Create('Clipboard copy operation failed: HasFormat');
|
||||
// Copy it in our custom format so we know what kind of block it is.
|
||||
// That effects how it is pasted in.
|
||||
BufSize:=SLen+SizeOf(TSynSelectionMode)+1;
|
||||
GetMem(Buf,BufSize);
|
||||
if Buf<>nil then
|
||||
if Buf = nil then
|
||||
raise ESynEditError.Create('Clipboard copy operation failed: GetMem');
|
||||
try
|
||||
P:=PChar(Buf);
|
||||
// Our format: TSynSelectionMode value followed by text.
|
||||
@ -1323,17 +1319,13 @@ begin
|
||||
inc(P,SLen);
|
||||
end;
|
||||
P[0]:=#0;
|
||||
try
|
||||
Failed:=not Clipboard.AddFormat(SynEditClipboardFormat,Buf^,BufSize);
|
||||
except
|
||||
end;
|
||||
if not Clipboard.AddFormat(SynEditClipboardFormat,Buf^,BufSize) then
|
||||
raise ESynEditError.Create('Clipboard copy operation failed: AddFormat');
|
||||
finally
|
||||
FreeMem(Buf);
|
||||
end;
|
||||
end;
|
||||
if Failed then
|
||||
raise ESynEditError.Create('Clipboard copy operation failed');
|
||||
{$ELSE}
|
||||
Failed := true; // assume the worst.
|
||||
// Open and Close are the only TClipboard methods we use because TClipboard
|
||||
// is very hard (impossible) to work with if you want to put more than one
|
||||
// format on it at a time.
|
||||
@ -1385,7 +1377,6 @@ begin
|
||||
end;
|
||||
{$ENDIF}
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TCustomSynEdit.CopyToClipboard;
|
||||
begin
|
||||
|
Loading…
Reference in New Issue
Block a user