Jump to content
Codehunter

Feature Request for String Paste As

Recommended Posts

Hello!

 

Would be nice to have an type "%s +" in the PasteAs options for SQL statements. There is not neccessary to include any linebreak in the string itself, only in the Pascal source.

LSQL := 'SELECT * ' +
        'FROM myTable ' +
        'WHERE myCol=1 ' +
        'ORDER BY id DESC';

Please note the space prior to the closing quotemark in each line.

 

Greetz

Cody

Share this post


Link to post

I totally agree, and it has been suggested for years.
No joy so far.

Unneeded whitespace and linebreaks should be eliminated.

LSQL := "SELECT * 
        FROM myTable 
        WHERE myCol=1 
        ORDER BY id DESC";

 

  • Like 2

Share this post


Link to post

That is so easy, a little wizard with 2 menus.

 

Forgive me for the code quality, looks like I did not give too much flamingos about it.

 

image.png.6958938948e78868bbe111a94de9c9f6.png

 

// Paste
procedure TClipboardWizard.mePasteFromClipboard(Sender: TObject);
begin
  with BorlandIDEServices as IOTAEditorServices do
    if Assigned(TopView) then
    begin
      TopView.Buffer.EditPosition.InsertText(GetFormattedString);
      TopView.Paint; // invalidation
    end;
end;

function TClipboardWizard.GetFormattedString: string;
var
  List: TStringList;
  q: integer;
begin
  if Clipboard.HasFormat(CF_TEXT) then
  begin
    List := TStringList.Create;
    try
      List.Text := Clipboard.AsText;

      for q := 0 to List.Count - 2 do
        List[q] := #39 + List[q].Trim.Replace(#39, #39#39) + #32#39#43#32#47#47;

      q := List.Count - 1;
      List[q] := #39 + List[q].Trim.Replace(#39, #39#39) + #32#39#59#32#47#47;

      Result := List.Text;
    finally
      List.Free;
    end;
  end;
end;


 

//Copy
procedure TClipboardWizard.meCopyToClipboard(Sender: TObject);
begin
  with BorlandIDEServices as IOTAEditorServices do
    if Assigned(TopView) then
      Clipboard.AsText := RemoveUnneededChars(TopView.Block.Text);
end;

function TClipboardWizard.RemoveUnneededChars(const Value: string): string;
var
  List: TStringList;
  q: integer;
begin
  if Value.Trim <> '' then
  begin
    List := TStringList.Create;
    try
      List.Text := Value;
      for q := 0 to List.Count - 1 do
        List[q] := List[q].Trim([#32, #33, #34, #35, #36, #37, #38, #40, #41, #42, #43, #44, #45, #46, #47, #48, #49, #50, #51, #52, #53, #54, #55, #56, #57, #58, #59, #60, #61, #62, #63, #64, #65, #66, #67, #68, #69, #70, #71, #72, #73, #74, #75, #76,
          #77, #78, #79, #80, #81, #82, #83, #84, #85, #86, #87, #88, #89, #90, #91, #92, #93, #94, #95, #96, #97, #98, #99, #100, #101, #102, #103, #104, #105, #106, #107, #108, #109, #110, #111, #112, #113, #114, #115, #116, #117, #118, #119, #120,
          #121, #122, #123, #124, #125, #126, #127]).Replace(#39#39#39, #39#39#32#39).Trim([#39]).Replace(#39#39, #39);
      Result := List.Text;
    finally
      List.Free;
    end;
  end
  else
    Result := '';
end;

 

Edited by Attila Kovacs

Share this post


Link to post
6 minutes ago, Lars Fosdal said:

I totally agree, and it has been suggested for years.
No joy so far.

Unneeded whitespace and linebreaks should be eliminated.


LSQL := "SELECT * 
        FROM myTable 
        WHERE myCol=1 
        ORDER BY id DESC";

 

But your snippet seems to be like pseudocode, its not Delphi/Pascal 🙂 I'm used such constructs in PHP and let the DBMS strip all unneeded stuff. But Delphi/Pascal doesnt support multiline strings like in your snippet.

 

The resulting SQL Statement should be:

SELECT * FROM myTable WHERE myCol=1 ORDER BY id DESC

 

10 minutes ago, Arnaud Bouchez said:

Some tools - like cnpack IIRC - allow to format the text into source code string after being pasted.

Oh yeah, lets remove all the stuff from GExperts which exists in other Tools 😉 The Apple Way: Nothing can exist in our Appstore that is already offered by us. 🤬

IMHO the best way is a competition between the best ideas. I know that other IDE experts have similar or better implementations but why not improve GExperts? Sometimes the others are unstable or unusable in some situations. Esp. CnPack is very tricky in the Editor Experts, therefore I have completely disabled this part.

Share this post


Link to post

It is pseudocode - the way we'd want it to work - and as I said, there has been QP or QC's created for this before.

  • Thanks 1

Share this post


Link to post
12 minutes ago, Lars Fosdal said:

It is pseudocode - the way we'd want it to work - and as I said, there has been QP or QC's created for this before.

This was not meant as critic 🙂 As you can see at the left, I'm not so often here... Mostly in the german DP

Share this post


Link to post
4 hours ago, Lars Fosdal said:

I totally agree, and it has been suggested for years.
No joy so far.

Where?

Share this post


Link to post
17 hours ago, Lars Fosdal said:

I totally agree, and it has been suggested for years.
No joy so far.

Unneeded whitespace and linebreaks should be eliminated.


LSQL := "SELECT * 
        FROM myTable 
        WHERE myCol=1 
        ORDER BY id DESC";

 

This is the only one language feature I want to be added to Delphi if I can choose only one.

I think it's called multi-line string literals?

I think use we should keep using the single quotes, because sometimes we have double quotes in the string when working with html or SQL.

Share this post


Link to post
On 11/11/2020 at 11:22 AM, Codehunter said:

Would be nice to have an type "%s +" in the PasteAs options for SQL statements. There is not neccessary to include any linebreak in the string itself, only in the Pascal source.


LSQL := 'SELECT * ' +
        'FROM myTable ' +
        'WHERE myCol=1 ' +
        'ORDER BY id DESC';

 

Have you looked at the newer "Convert Strings" expert? There is a favorite called "SQL-to-String" which seems to do exactly what you want

Edited by dummzeuch

Share this post


Link to post
On 11/14/2020 at 1:51 PM, dummzeuch said:

Have you looked at the newer "Convert Strings" expert? There is a favorite called "SQL-to-String" which seems to do exactly what you want

Thanks! This is exactly what I want. But a little confusing. Maybe the Convert Strings expert can supercede the String Paste as expert because the last is a subset of the first.

Share this post


Link to post
2 hours ago, Codehunter said:

Thanks! This is exactly what I want. But a little confusing. Maybe the Convert Strings expert can supercede the String Paste as expert because the last is a subset of the first.

I wrote the Convert Strings expert several months after somebody else donated the String Paste expert, because I could never remember how to use the latter. I always wanted to clean up this mess, but never came around doing it.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×