Author Topic: Compilation error??  (Read 953 times)


  • Newbie
  • Posts: 2
Compilation error??
« on: July 21, 2021, 05:59:19 am »

I have used Delphi before and I just installed 2.0.6 version. I am running Linux Min 21.04 in an old 4th generation x64 notebook, with 4 GB of memory.

I wrote a simple app and still in its infancy. I found a variable (used as an index for an array of strings) gets corrupted after the new data in written into the array of strings, after the index to the array is incremented. I discovered because I kept getting error during run-time due to memory boundary issue. I think I have correctly declared the array of strings correctly, initially as

category = string[16] ;
catDB := array [1..1024] of category ;

 and laater to catDB := array [1..1024] of string[16] ;

Enclosed is the project zip. In 'procedure TfrmMyDB.cbxCategoryKeyUp', 

           if (MessageDlg ('Category name', 'Save category name into category database?', mtConfirmation, [mbYes, mbNo], 0)
           = mrYes) then
            //  Save category into category database
            newcat := cbxCategory.Text ; <----- please breakpoint here and step down
            catDB[catCnt] := newcat ; <---- please view catcnt before and after trace and you see catcnt gets corrupted.
            catCnt := catCnt + 1 ; <------ 1st character in the array is incremented
            frmMyDB.StatusBar.Panels.Items[0].Text := 'Category ' + newcat + ' saved.' ;

On the first field "category" data entry, newcat correcctly receives the text from the edit control.
Please check the value of catcnt before and after the statement is stepped. Before stepping, catcnt = 0 but altered after stepped to a value > 170000.

Step down to catcnt := catcnt + 1 ; The first character in catDB will be altered. In my test, I entered "Email". On subsequent, field entry into catDB, in "find_cat", the character "E" in 'Email' is changed to "F".  I found this issue in function find_cat, i.e. temporary strings were used to determined their strings.

Is this due to my programming problem or is this a compilation issue. I do not anticipate the my error in catcnt and slightly be different due to different machine.

Appreciate your response. Thanks .. sunTan


TinyPortal © 2005-2018