-2

I use this code to log the many lines (SQL.Add) making complex scripts i have to build:

Ex:

[...]
SQL.Add('ENTITY_ID, PRO_CODE, PHASE_CODE, TASK_CODE, PERIOD_REF');
SQL.Add('from ' + trim(SourceJrnl) + ' where');
SQL.Add('MASTER_ID = ' + IntToStr(TranID) + ' and');...
[...]


{ for debugging only }
for i := 0 to SQL.Count-1 do 
  ShowMessage('Line #' + IntToStr(i+1) + ' : '+ SQL.Strings[i]);

Any simple way (function) to have the lines written to a file out of a stringlist or memo.

[EDIT] Sorry. NO memo or stringlist but a simple log file.

volvox
  • 1,194
  • 6
  • 22
  • 29
  • Your question make no sense. If you want this written in a memo, just write it there, or explain better what are you after. – jachguate Mar 20 '13 at 00:52
  • 2
    MyMemo.Lines.Assign( SQL ) – Sir Rufo Mar 20 '13 at 00:53
  • Sorry - i'm rather want the lines to be logged in a text file. It would be nice to have a log function or non visual component. thanks – volvox Mar 20 '13 at 01:12
  • 2
    SQL.SaveToFile?, or to append to an existing file SQL.SaveToStream(filestream) – Gerry Coll Mar 20 '13 at 01:17
  • edited question based on comments above. Volvox a bit more effort writing your question would be good. – Warren P Mar 20 '13 at 01:34
  • OK thanks - SQL.SaveToFile will do the job. Since i have many different SQL scripts on the same unit i will do With SQL1 ... do SQL1.SQL.SaveToFile() ....etc. Thanks – volvox Mar 20 '13 at 01:34

1 Answers1

2

Calling SQL.SaveToFile will write the query to a file, but it will clobber the previous file contents, so you can only see one query and no other logs. Instead, read the SQL.Text property to get all the lines in a single string, and then write it to your log file using whatever logging technique you have for the rest of your program. In a pinch, a simple way to write a line of text to a file is to call Writeln, but people have asked about real logging libraries before.

Community
  • 1
  • 1
Rob Kennedy
  • 161,384
  • 21
  • 275
  • 467