Lazarus = 3.99 FPC = 3.3.1. MacOs Monterey 12.7.5
I am attempting to debug what was a working GUI program, a change in input data seems to have caused occasional records to be "lost". Since I am developing on MACOS I cannot access the message window as I think can be done in Windoze environment. However I can (usually) manage by adding WriteLn statements at appropriate places in the code and then running my compiled program from a terminal window. ShowMessage does output but this is not a convenient solution as I have to be present to look and copy output if necessary. I would like to be able to leave the conversion running and then come back later to copy/look at all the debug output.
My program is started from a button in Unit1, it calls a function in another Unit to add records to my database. WriteLn statements in the main Unit1 appear in terminal window as expected. WriteLn statements in the second unit do not output to the terminal window. It seems that it only from the second Unit that I cannot output to terminal window.
I would appreciate help or suggestions to fix this problem.
The terminal window output and function code is as follows. I have indicated where output is called and where I would have expected it to occur in the output
Table Units Created
Table Inverters Created
Table TmpDays Created
Table Days Created
Table Times Created
1 records added to table Units <<<<<WriteLn output should appear here
3 records added to table Inverters
2947 records added to table TmpDays
Duplicate Time Record found: 2018/02/18 14:06
Duplicate Time Record found: 2019/03/16 13:52
Duplicate Time Record found: 2020/07/25 11:09
Duplicate Time Record found: 2021/10/17 11:17
In TblDataAddDaysTimes: Date 2024/02/24 No matching time records
In TblDataAddDaysTimes: Date 2024/02/25 No matching time records
In TblDataAddDaysTimes: Date 2024/02/26 No matching time records
In TblDataAddDaysTimes: Date 2024/02/27 No matching time records
2943 records added to table Days
218308 records added to table Times
The Function code is
Function tblDataAddInverters(Const txtFile:String; Out icount:int32) : boolean;
//Read comma delimeted file and write inverter records to database table
Var
iRecs: Int32; //record count of added records
txtF: TextFile;
strLine: String;
strArray: TStringArray;
strColNames: String;
strColUnits: String;
begin
Result:=False;
iRecs:=0;
Try
//Lookup ColNames & ColUnits form table Units
strColNames:=GetStringFromTable('ColNames', 'Units', 'UnitID', '1');
strColUnits:=GetStringFromTable('ColUnits', 'Units', 'UnitID', '1');
AssignFile(txtF, txtFile);
Reset(txtF);
dbTrans.Active:=True;
ReadLn(txtF, strLine); //Skip over column headers
While not EOF(txtF) do
Begin
ReadLn(txtF, strLine);
iRecs:= iRecs + 1;
WriteLn(strLine); //// <<<<<<<<<<<<<<<<<<<<<no output
ShowMessage(IntToStr(iRecs) + ' ' +strLine);
strArray:=strLine.Split(',');
//Insert Records here
sqlite3.ExecuteDirect('INSERT INTO "Inverters" (' +
'"SystemName", ' +
'"ModelNo", ' +
'"MPPT", ' +
'"ColNames", ' +
'"ColUnits"' +
' )' +
'VALUES (' +
//DoNullStr(strArray[0]) + ',' +
DoNullStr(strArray[1]) + ',' +
DoNullStr(strArray[2]) + ',' +
DoNullStr(strArray[3]) + ',' +
QuotedStr(strColNames) + ',' +
QuotedStr(strColUnits) +
')');
//'"' + strColNames + '",' +
//'"' + strColUnits + '"' +
Form1.txtInverters.Text:=IntToStr(iRecs); //Take care here to avoid circular reference
{EndWhile}End;
//Commit changes to DataBase
dbTrans.Commit;
iCount:=iRecs;
Result:=True;
//Close text file
Close(txtF);
Except
On E: Exception Do
Begin
WriteLn('Error in tblDataAddInverters :' + E.Message);
Result:=False;
iCount:=0;
End;
{EndTry}end;
end;