Mikayil Abdullayev
Mikayil Abdullayev

Reputation: 12376

Delphi - How to break string concatenation into several lines

I have a long SQL text that I want to assign to a query SQL. I do this the following way:

SQL.Text:= 'SELECT T1.COLUMN1,T2.COLUMN2,T1COLUMN3..........,'+
          ' T1.COLUMNn FROM TABLE1 T1 INNER JOIN '+
          ' TABLE2 T2 ON T1.ID=T2.ID'+
          ' WHERE T1.COLUMN10=100'

The actual SQL is 20 times longer than this. My problem is with the line breaks. When I format the source code (Ctrl+D) it sometimes leaves the lines as I typed, but other times it deletes the line breaks and I get something like this:

 'SELECT T1.COLUMN1,T2.COLUMN2,T1COLUMN3 ' + 'FROM TABLE1 T1 INNER JOIN '+  'TABLE2 T2 ON T1.ID=T2.ID'

And this leads to a "line too long (more than 1023 charactes)" error. What's interesting is this does not happen with all lines. I can't catch the difference between the lines which will be affected and those that won't. I need a line break after or before the "+" sign. How do I do this?

Upvotes: 3

Views: 3529

Answers (2)

Ravaut123
Ravaut123

Reputation: 2818

You can also use the Add function.

SQL.Clear;
SQL.ADD('SELECT T1.COLUMN1,T2.COLUMN2,T1COLUMN3..........,');
SQL.ADD(' T1.COLUMNn FROM TABLE1 T1 INNER JOIN');
SQL.ADD(' TABLE2 T2 ON T1.ID=T2.ID');
SQL.ADD(' WHERE T1.COLUMN10=100');

Upvotes: 14

Cleankod
Cleankod

Reputation: 2340

Try to assign the value in every line:

SQL.Text := 'SELECT T1.COLUMN1,T2.COLUMN2,T1COLUMN3..........,';
SQL.Text := SQL.Text + ' T1.COLUMNn FROM TABLE1 T1 INNER JOIN ';
SQL.Text := SQL.Text + ' TABLE2 T2 ON T1.ID=T2.ID';
SQL.Text := SQL.Text + ' WHERE T1.COLUMN10=100';

I know it looks ugly, but I think it solves your problem.

Upvotes: -1

Related Questions